Skip to content

Instantly share code, notes, and snippets.

@phemmer
Created April 22, 2015 16:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phemmer/31a250b9cad0ee049404 to your computer and use it in GitHub Desktop.
Save phemmer/31a250b9cad0ee049404 to your computer and use it in GitHub Desktop.
go bcrypt benchmark
package main
import (
"testing"
"golang.org/x/crypto/bcrypt"
)
func BenchmarkBcrypt4(b *testing.B) {
benchBcrypt(b, 4)
}
func BenchmarkBcrypt5(b *testing.B) {
benchBcrypt(b, 5)
}
func BenchmarkBcrypt6(b *testing.B) {
benchBcrypt(b, 6)
}
func BenchmarkBcrypt7(b *testing.B) {
benchBcrypt(b, 7)
}
func BenchmarkBcrypt8(b *testing.B) {
benchBcrypt(b, 8)
}
func BenchmarkBcrypt9(b *testing.B) {
benchBcrypt(b, 9)
}
func BenchmarkBcrypt10(b *testing.B) {
benchBcrypt(b, 10)
}
func benchBcrypt(b *testing.B, cost int) {
b.StopTimer()
pass, _ := bcrypt.GenerateFromPassword([]byte("foo bar"), cost)
b.StartTimer()
for i := 0; i < b.N; i++ {
bcrypt.CompareHashAndPassword(pass, []byte("foo bar"))
}
}
# go test -v -bench=.
testing: warning: no tests to run
PASS
BenchmarkBcrypt4 1000 1779279 ns/op
BenchmarkBcrypt5 500 3227878 ns/op
BenchmarkBcrypt6 200 6379871 ns/op
BenchmarkBcrypt7 100 12690109 ns/op
BenchmarkBcrypt8 50 25364979 ns/op
BenchmarkBcrypt9 30 50730959 ns/op
BenchmarkBcrypt10 10 100569334 ns/op
ok tmp/dme 12.430s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment