simplify code

This commit is contained in:
lijunlong 2020-04-01 09:41:26 +08:00
parent 7c15d1e8c3
commit 8c05251cce

View File

@ -6,53 +6,33 @@ import (
"testing" "testing"
) )
func Benchmark_blsSigner_Sign(b *testing.B) { func BenchmarkBLSSign(b *testing.B) {
signer := blsSigner{} signer := blsSigner{}
b.ResetTimer() for i := 0; i < b.N; i++ {
for i:=0;i<b.N;i++{
b.StopTimer() b.StopTimer()
pk, err := signer.GenPrivate() pk, _ := signer.GenPrivate()
if err != nil {
b.Error(err)
}
randMsg := make([]byte, 32) randMsg := make([]byte, 32)
rand.Read(randMsg) rand.Read(randMsg)
b.StartTimer() b.StartTimer()
_, err = signer.Sign(pk, randMsg)
if err != nil { _, _ = signer.Sign(pk, randMsg)
b.Error(err)
}
} }
} }
func Benchmark_blsSigner_Verify(b *testing.B) { func BenchmarkBLSVerify(b *testing.B) {
signer := blsSigner{} signer := blsSigner{}
b.ResetTimer() for i := 0; i < b.N; i++ {
for i:=0;i<b.N;i++{
b.StopTimer() b.StopTimer()
priv, err := signer.GenPrivate()
if err != nil {
b.Error(err)
}
randMsg := make([]byte, 32) randMsg := make([]byte, 32)
rand.Read(randMsg) rand.Read(randMsg)
sig, err := signer.Sign(priv, randMsg)
if err != nil { priv, _ := signer.GenPrivate()
b.Error(err) pk, _ := signer.ToPublic(priv)
} addr, _ := address.NewBLSAddress(pk)
pk, err := signer.ToPublic(priv) sig, _ := signer.Sign(priv, randMsg)
if err != nil {
b.Error(err)
}
addr, err := address.NewBLSAddress(pk)
if err != nil {
b.Error(err)
}
b.StartTimer() b.StartTimer()
err = signer.Verify(sig, addr, randMsg)
if err != nil { _ = signer.Verify(sig, addr, randMsg)
b.Error(err)
}
} }
} }