Merge pull request #1470 from hunjixin/hunjixin/test/bls_benchmarks
add bench mark for bls sign and verify
This commit is contained in:
commit
9030b559e8
38
lib/sigs/bls/bls_bench_test.go
Normal file
38
lib/sigs/bls/bls_bench_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package bls
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"github.com/filecoin-project/go-address"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkBLSSign(b *testing.B) {
|
||||
signer := blsSigner{}
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
pk, _ := signer.GenPrivate()
|
||||
randMsg := make([]byte, 32)
|
||||
rand.Read(randMsg)
|
||||
b.StartTimer()
|
||||
|
||||
_, _ = signer.Sign(pk, randMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBLSVerify(b *testing.B) {
|
||||
signer := blsSigner{}
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
randMsg := make([]byte, 32)
|
||||
rand.Read(randMsg)
|
||||
|
||||
priv, _ := signer.GenPrivate()
|
||||
pk, _ := signer.ToPublic(priv)
|
||||
addr, _ := address.NewBLSAddress(pk)
|
||||
sig, _ := signer.Sign(priv, randMsg)
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
_ = signer.Verify(sig, addr, randMsg)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user