lotus/lib/sigs/bls/bls_bench_test.go

40 lines
720 B
Go
Raw Normal View History

2020-03-28 04:31:16 +00:00
package bls
import (
"crypto/rand"
"testing"
"github.com/filecoin-project/go-address"
2020-03-28 04:31:16 +00:00
)
2020-04-01 01:41:26 +00:00
func BenchmarkBLSSign(b *testing.B) {
2020-03-28 04:31:16 +00:00
signer := blsSigner{}
2020-04-01 01:41:26 +00:00
for i := 0; i < b.N; i++ {
2020-03-28 04:31:16 +00:00
b.StopTimer()
2020-04-01 01:41:26 +00:00
pk, _ := signer.GenPrivate()
2020-03-28 04:31:16 +00:00
randMsg := make([]byte, 32)
_, _ = rand.Read(randMsg)
2020-03-28 04:31:16 +00:00
b.StartTimer()
2020-04-01 01:41:26 +00:00
_, _ = signer.Sign(pk, randMsg)
2020-03-28 04:31:16 +00:00
}
}
2020-04-01 01:41:26 +00:00
func BenchmarkBLSVerify(b *testing.B) {
2020-03-28 04:31:16 +00:00
signer := blsSigner{}
2020-04-01 01:41:26 +00:00
for i := 0; i < b.N; i++ {
2020-03-28 04:31:16 +00:00
b.StopTimer()
randMsg := make([]byte, 32)
_, _ = rand.Read(randMsg)
2020-04-01 01:41:26 +00:00
priv, _ := signer.GenPrivate()
pk, _ := signer.ToPublic(priv)
addr, _ := address.NewBLSAddress(pk)
sig, _ := signer.Sign(priv, randMsg)
2020-03-28 04:31:16 +00:00
b.StartTimer()
2020-04-01 01:41:26 +00:00
_ = signer.Verify(sig, addr, randMsg)
2020-03-28 04:31:16 +00:00
}
2020-04-01 01:41:26 +00:00
}