forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
To run Bcrypt benchmarks: | ||
|
||
```bash | ||
go test -bench . | ||
``` | ||
|
||
On the test machine (midrange ThinkPad; i7 6600U), this results in: | ||
|
||
```bash | ||
goos: linux | ||
goarch: amd64 | ||
pkg: github.com/cosmos/cosmos-sdk/crypto/keys/mintkey | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-9-4 50 34609268 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-10-4 20 67874471 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-11-4 10 135515404 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-12-4 5 274824600 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-13-4 2 547012903 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-14-4 1 1083685904 ns/op | ||
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-15-4 1 2183674041 ns/op | ||
PASS | ||
ok github.com/cosmos/cosmos-sdk/crypto/keys/mintkey 12.093s | ||
``` | ||
|
||
Benchmark results are in nanoseconds, so security parameter 12 takes about a quarter of a second to generate the Bcrypt key, security param 13 takes half a second, and so on. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mintkey | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"golang.org/x/crypto/bcrypt" | ||
|
||
"github.com/tendermint/tendermint/crypto" | ||
) | ||
|
||
func BenchmarkBcryptGenerateFromPassword(b *testing.B) { | ||
passphrase := []byte("passphrase") | ||
for securityParam := 9; securityParam < 16; securityParam++ { | ||
param := securityParam | ||
b.Run(fmt.Sprintf("benchmark-security-param-%d", param), func(b *testing.B) { | ||
saltBytes := crypto.CRandBytes(16) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := bcrypt.GenerateFromPassword(saltBytes, passphrase, param) | ||
require.Nil(b, err) | ||
} | ||
}) | ||
} | ||
} |