prysm-pulse/shared/bls/blst/bls_benchmark_test.go
Nishant Das 77c95f3051
Add New Compiler Flags for BLST (#7352)
* add new c opts
* remove
* add to asm
* fix up benchamrks
* Merge refs/heads/master into addNewOpts
2020-09-26 08:48:02 +00:00

61 lines
1.2 KiB
Go

// +build linux,amd64 linux,arm64
package blst_test
import (
"testing"
"github.com/prysmaticlabs/prysm/shared/bls/blst"
"github.com/prysmaticlabs/prysm/shared/bls/iface"
)
func BenchmarkSignature_Verify(b *testing.B) {
sk := blst.RandKey()
msg := []byte("Some msg")
sig := sk.Sign(msg)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if !sig.Verify(sk.PublicKey(), msg) {
b.Fatal("could not verify sig")
}
}
}
func BenchmarkSignature_AggregateVerify(b *testing.B) {
sigN := 128 // MAX_ATTESTATIONS per block.
var pks []iface.PublicKey
var sigs []iface.Signature
var msgs [][32]byte
for i := 0; i < sigN; i++ {
msg := [32]byte{'s', 'i', 'g', 'n', 'e', 'd', byte(i)}
sk := blst.RandKey()
sig := sk.Sign(msg[:])
pks = append(pks, sk.PublicKey())
sigs = append(sigs, sig)
msgs = append(msgs, msg)
}
aggregated := blst.Aggregate(sigs)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if !aggregated.AggregateVerify(pks, msgs) {
b.Fatal("could not verify aggregate sig")
}
}
}
func BenchmarkSecretKey_Marshal(b *testing.B) {
key := blst.RandKey()
d := key.Marshal()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := blst.SecretKeyFromBytes(d)
_ = err
}
}