title: Which bcrypt cost to use for 2018?
body: <h1>Update</h1>
  
  <p>Actually it seems the benchmark was incorrectly setup I have followed the <a href="https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go" rel="noreferrer">resource shared</a> by user @Luke Joshua Park and now it works.</p>
  
  <pre><code>package main
  
  import "testing"
  
  func benchmarkBcrypt(i int, b *testing.B){
      for n:= 0; n &lt; b.N; n++ {
          HashPassword("my pass", i)
          }
  
  }
  
  func BenchmarkBcrypt9(b *testing.B){
      benchmarkBcrypt(9, b)
  }
  
  func BenchmarkBcrypt10(b *testing.B){
      benchmarkBcrypt(10, b)
  }
  
  func BenchmarkBcrypt11(b *testing.B){
      benchmarkBcrypt(11, b)
  }
  
  func BenchmarkBcrypt12(b *testing.B){
      benchmarkBcrypt(12, b)
  }
  
  func BenchmarkBcrypt13(b *testing.B){
      benchmarkBcrypt(13, b)
  }
  
  func BenchmarkBcrypt14(b *testing.B){
      benchmarkBcrypt(14, b)
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>BenchmarkBcrypt9-4            30      39543095 ns/op
  BenchmarkBcrypt10-4           20      79184657 ns/op
  BenchmarkBcrypt11-4           10     158688315 ns/op
  BenchmarkBcrypt12-4            5     316070133 ns/op
  BenchmarkBcrypt13-4            2     631838101 ns/op
  BenchmarkBcrypt14-4            1    1275047344 ns/op
  PASS
  ok      go-playground   10.670s
  </code></pre>
  
  <hr>
  
  <h1>Old incorrect benchmark</h1>
  
  <p>I have a small set on benchmark test in golang and am curios of to what is a recommended bcrypt cost to use as of May 2018. </p>
  
  <p>This is my benchrmark file:</p>
  
  <pre><code>package main
  
  import "testing"
  
  func BenchmarkBcrypt10(b *testing.B){
      HashPassword("my pass", 10)
  }
  
  func BenchmarkBcrypt12(b *testing.B){
      HashPassword("my pass", 12)
  }
  
  func BenchmarkBcrypt13(b *testing.B){
      HashPassword("my pass", 13)
  }
  
  
  func BenchmarkBcrypt14(b *testing.B){
      HashPassword("my pass", 14)
  }
  
  func BenchmarkBcrypt15(b *testing.B){
      HashPassword("my pass", 15)
  }
  </code></pre>
  
  <p>and this is <code>HashPassword()</code> func inside <code>main.go</code>:</p>
  
  <pre><code>import (
      "golang.org/x/crypto/bcrypt"
  )
  
  func HashPassword(password string, cost int) (string, error) {
      bytes, err := bcrypt.GenerateFromPassword([]byte(password), cost)
      return string(bytes), err
  }
  </code></pre>
  
  <p>The current output is:</p>
  
  <pre><code>go test -bench=.
  BenchmarkBcrypt10-4     2000000000           0.04 ns/op
  BenchmarkBcrypt12-4     2000000000           0.16 ns/op
  BenchmarkBcrypt13-4     2000000000           0.32 ns/op
  BenchmarkBcrypt14-4            1    1281338532 ns/op
  BenchmarkBcrypt15-4            1    2558998327 ns/op
  PASS
  </code></pre>
  
  <p>It seems that for a bcrypt with cost of 13 the time it takes is 0.32 nanoseconds, and for cost 14 the time is 1281338532ns or ~1.2 seconds
  Which I believe is too much. What do is the best bcrypt cost to use for the current year 2018.</p>