github.com/number571/tendermint@v0.34.11-gost/crypto/gost512/bench_test.go (about) 1 package gost512 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/number571/tendermint/crypto" 8 "github.com/number571/tendermint/crypto/internal/benchmarking" 9 "github.com/stretchr/testify/require" 10 ) 11 12 const ( 13 TEST_SUBJECT = "subject" 14 TEST_PASSWORD = "password" 15 ) 16 17 func BenchmarkSigning(b *testing.B) { 18 priv := GenPrivKeyWithInput(TEST_SUBJECT, TEST_PASSWORD) 19 benchmarking.BenchmarkSigning(b, priv) 20 } 21 22 func BenchmarkVerification(b *testing.B) { 23 priv := GenPrivKeyWithInput(TEST_SUBJECT, TEST_PASSWORD) 24 benchmarking.BenchmarkVerification(b, priv) 25 } 26 27 func BenchmarkVerifyBatch(b *testing.B) { 28 msg := []byte("BatchVerifyTest") 29 30 for _, sigsCount := range []int{1, 8, 64, 512} { 31 sigsCount := sigsCount 32 b.Run(fmt.Sprintf("sig-count-%d", sigsCount), func(b *testing.B) { 33 // Pre-generate all of the keys, and signatures, but do not 34 // benchmark key-generation and signing. 35 pubs := make([]crypto.PubKey, 0, sigsCount) 36 sigs := make([][]byte, 0, sigsCount) 37 for i := 0; i < sigsCount; i++ { 38 priv := GenPrivKeyWithInput(TEST_SUBJECT, TEST_PASSWORD) 39 sig, _ := priv.Sign(msg) 40 pubs = append(pubs, priv.PubKey().(PubKey)) 41 sigs = append(sigs, sig) 42 } 43 b.ResetTimer() 44 45 b.ReportAllocs() 46 // NOTE: dividing by n so that metrics are per-signature 47 for i := 0; i < b.N/sigsCount; i++ { 48 // The benchmark could just benchmark the Verify() 49 // routine, but there is non-trivial overhead associated 50 // with BatchVerifier.Add(), which should be included 51 // in the benchmark. 52 v := NewBatchVerifier() 53 for i := 0; i < sigsCount; i++ { 54 err := v.Add(pubs[i], msg, sigs[i]) 55 require.NoError(b, err) 56 } 57 58 if ok, _ := v.Verify(); !ok { 59 b.Fatal("signature set failed batch verification") 60 } 61 } 62 }) 63 } 64 }