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.

116 lines
2.7 KiB

  1. package certifiers_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/tendermint/tendermint/certifiers"
  6. )
  7. func BenchmarkGenCommit20(b *testing.B) {
  8. keys := certifiers.GenValKeys(20)
  9. benchmarkGenCommit(b, keys)
  10. }
  11. func BenchmarkGenCommit100(b *testing.B) {
  12. keys := certifiers.GenValKeys(100)
  13. benchmarkGenCommit(b, keys)
  14. }
  15. func BenchmarkGenCommitSec20(b *testing.B) {
  16. keys := certifiers.GenSecpValKeys(20)
  17. benchmarkGenCommit(b, keys)
  18. }
  19. func BenchmarkGenCommitSec100(b *testing.B) {
  20. keys := certifiers.GenSecpValKeys(100)
  21. benchmarkGenCommit(b, keys)
  22. }
  23. func benchmarkGenCommit(b *testing.B, keys certifiers.ValKeys) {
  24. chainID := fmt.Sprintf("bench-%d", len(keys))
  25. vals := keys.ToValidators(20, 10)
  26. for i := 0; i < b.N; i++ {
  27. h := 1 + i
  28. appHash := []byte(fmt.Sprintf("h=%d", h))
  29. keys.GenCommit(chainID, h, nil, vals, appHash, 0, len(keys))
  30. }
  31. }
  32. // this benchmarks generating one key
  33. func BenchmarkGenValKeys(b *testing.B) {
  34. keys := certifiers.GenValKeys(20)
  35. for i := 0; i < b.N; i++ {
  36. keys = keys.Extend(1)
  37. }
  38. }
  39. // this benchmarks generating one key
  40. func BenchmarkGenSecpValKeys(b *testing.B) {
  41. keys := certifiers.GenSecpValKeys(20)
  42. for i := 0; i < b.N; i++ {
  43. keys = keys.Extend(1)
  44. }
  45. }
  46. func BenchmarkToValidators20(b *testing.B) {
  47. benchmarkToValidators(b, 20)
  48. }
  49. func BenchmarkToValidators100(b *testing.B) {
  50. benchmarkToValidators(b, 100)
  51. }
  52. // this benchmarks constructing the validator set (.PubKey() * nodes)
  53. func benchmarkToValidators(b *testing.B, nodes int) {
  54. keys := certifiers.GenValKeys(nodes)
  55. for i := 1; i <= b.N; i++ {
  56. keys.ToValidators(int64(2*i), int64(i))
  57. }
  58. }
  59. func BenchmarkToValidatorsSec100(b *testing.B) {
  60. benchmarkToValidatorsSec(b, 100)
  61. }
  62. // this benchmarks constructing the validator set (.PubKey() * nodes)
  63. func benchmarkToValidatorsSec(b *testing.B, nodes int) {
  64. keys := certifiers.GenSecpValKeys(nodes)
  65. for i := 1; i <= b.N; i++ {
  66. keys.ToValidators(int64(2*i), int64(i))
  67. }
  68. }
  69. func BenchmarkCertifyCommit20(b *testing.B) {
  70. keys := certifiers.GenValKeys(20)
  71. benchmarkCertifyCommit(b, keys)
  72. }
  73. func BenchmarkCertifyCommit100(b *testing.B) {
  74. keys := certifiers.GenValKeys(100)
  75. benchmarkCertifyCommit(b, keys)
  76. }
  77. func BenchmarkCertifyCommitSec20(b *testing.B) {
  78. keys := certifiers.GenSecpValKeys(20)
  79. benchmarkCertifyCommit(b, keys)
  80. }
  81. func BenchmarkCertifyCommitSec100(b *testing.B) {
  82. keys := certifiers.GenSecpValKeys(100)
  83. benchmarkCertifyCommit(b, keys)
  84. }
  85. func benchmarkCertifyCommit(b *testing.B, keys certifiers.ValKeys) {
  86. chainID := "bench-certify"
  87. vals := keys.ToValidators(20, 10)
  88. cert := certifiers.NewStatic(chainID, vals)
  89. check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), 0, len(keys))
  90. for i := 0; i < b.N; i++ {
  91. err := cert.Certify(check)
  92. if err != nil {
  93. panic(err)
  94. }
  95. }
  96. }