You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. package sr25519
  2. import (
  3. "fmt"
  4. "io"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/crypto"
  8. "github.com/tendermint/tendermint/crypto/internal/benchmarking"
  9. )
  10. func BenchmarkKeyGeneration(b *testing.B) {
  11. benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey {
  12. return genPrivKey(reader)
  13. }
  14. benchmarking.BenchmarkKeyGeneration(b, benchmarkKeygenWrapper)
  15. }
  16. func BenchmarkSigning(b *testing.B) {
  17. priv := GenPrivKey()
  18. benchmarking.BenchmarkSigning(b, priv)
  19. }
  20. func BenchmarkVerification(b *testing.B) {
  21. priv := GenPrivKey()
  22. benchmarking.BenchmarkVerification(b, priv)
  23. }
  24. func BenchmarkVerifyBatch(b *testing.B) {
  25. for _, n := range []int{1, 8, 64, 1024} {
  26. n := n
  27. b.Run(fmt.Sprintf("sig-count-%d", n), func(b *testing.B) {
  28. b.ReportAllocs()
  29. v := NewBatchVerifier()
  30. for i := 0; i < n; i++ {
  31. priv := GenPrivKey()
  32. pub := priv.PubKey()
  33. msg := []byte("BatchVerifyTest")
  34. sig, _ := priv.Sign(msg)
  35. err := v.Add(pub, msg, sig)
  36. require.NoError(b, err)
  37. }
  38. // NOTE: dividing by n so that metrics are per-signature
  39. for i := 0; i < b.N/n; i++ {
  40. if !v.Verify() {
  41. b.Fatal("signature set failed batch verification")
  42. }
  43. }
  44. })
  45. }
  46. }