github.com/prysmaticlabs/prysm@v1.4.4/shared/bls/blst/bls_benchmark_test.go (about) 1 // +build linux,amd64 linux,arm64 darwin,amd64 windows,amd64 2 // +build !blst_disabled 3 4 package blst_test 5 6 import ( 7 "testing" 8 9 "github.com/prysmaticlabs/prysm/shared/bls/blst" 10 "github.com/prysmaticlabs/prysm/shared/bls/common" 11 "github.com/prysmaticlabs/prysm/shared/testutil/require" 12 ) 13 14 func BenchmarkSignature_Verify(b *testing.B) { 15 sk, err := blst.RandKey() 16 require.NoError(b, err) 17 18 msg := []byte("Some msg") 19 sig := sk.Sign(msg) 20 21 b.ResetTimer() 22 for i := 0; i < b.N; i++ { 23 if !sig.Verify(sk.PublicKey(), msg) { 24 b.Fatal("could not verify sig") 25 } 26 } 27 } 28 29 func BenchmarkSignature_AggregateVerify(b *testing.B) { 30 sigN := 128 // MAX_ATTESTATIONS per block. 31 32 var pks []common.PublicKey 33 var sigs []common.Signature 34 var msgs [][32]byte 35 for i := 0; i < sigN; i++ { 36 msg := [32]byte{'s', 'i', 'g', 'n', 'e', 'd', byte(i)} 37 sk, err := blst.RandKey() 38 require.NoError(b, err) 39 sig := sk.Sign(msg[:]) 40 pks = append(pks, sk.PublicKey()) 41 sigs = append(sigs, sig) 42 msgs = append(msgs, msg) 43 } 44 aggregated := blst.AggregateSignatures(sigs) 45 46 b.ResetTimer() 47 b.ReportAllocs() 48 for i := 0; i < b.N; i++ { 49 if !aggregated.AggregateVerify(pks, msgs) { 50 b.Fatal("could not verify aggregate sig") 51 } 52 } 53 } 54 55 func BenchmarkSecretKey_Marshal(b *testing.B) { 56 key, err := blst.RandKey() 57 require.NoError(b, err) 58 d := key.Marshal() 59 60 b.ResetTimer() 61 for i := 0; i < b.N; i++ { 62 _, err := blst.SecretKeyFromBytes(d) 63 _ = err 64 } 65 }