Created
April 22, 2015 16:20
-
-
Save phemmer/31a250b9cad0ee049404 to your computer and use it in GitHub Desktop.
go bcrypt benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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