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.

117 lines
2.7 KiB

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