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.

105 lines
2.3 KiB

  1. package lite
  2. import (
  3. "testing"
  4. "time"
  5. dbm "github.com/tendermint/tm-db"
  6. "github.com/tendermint/tendermint/libs/log"
  7. "github.com/tendermint/tendermint/lite2/provider"
  8. mockp "github.com/tendermint/tendermint/lite2/provider/mock"
  9. dbs "github.com/tendermint/tendermint/lite2/store/db"
  10. )
  11. // NOTE: block is produced every minute. Make sure the verification time
  12. // provided in the function call is correct for the size of the blockchain. The
  13. // benchmarking may take some time hence it can be more useful to set the time
  14. // or the amount of iterations use the flag -benchtime t -> i.e. -benchtime 5m
  15. // or -benchtime 100x.
  16. //
  17. // Remember that none of these benchmarks account for network latency.
  18. var (
  19. benchmarkFullNode = mockp.New(GenMockNode(chainID, 1000, 100, 1, bTime))
  20. genesisHeader, _ = benchmarkFullNode.SignedHeader(1)
  21. )
  22. func BenchmarkSequence(b *testing.B) {
  23. c, err := NewClient(
  24. chainID,
  25. TrustOptions{
  26. Period: 24 * time.Hour,
  27. Height: 1,
  28. Hash: genesisHeader.Hash(),
  29. },
  30. benchmarkFullNode,
  31. []provider.Provider{benchmarkFullNode},
  32. dbs.New(dbm.NewMemDB(), chainID),
  33. Logger(log.TestingLogger()),
  34. SequentialVerification(),
  35. )
  36. if err != nil {
  37. b.Fatal(err)
  38. }
  39. b.ResetTimer()
  40. for n := 0; n < b.N; n++ {
  41. _, err = c.VerifyHeaderAtHeight(1000, bTime.Add(1000*time.Minute))
  42. if err != nil {
  43. b.Fatal(err)
  44. }
  45. }
  46. }
  47. func BenchmarkBisection(b *testing.B) {
  48. c, err := NewClient(
  49. chainID,
  50. TrustOptions{
  51. Period: 24 * time.Hour,
  52. Height: 1,
  53. Hash: genesisHeader.Hash(),
  54. },
  55. benchmarkFullNode,
  56. []provider.Provider{benchmarkFullNode},
  57. dbs.New(dbm.NewMemDB(), chainID),
  58. Logger(log.TestingLogger()),
  59. )
  60. if err != nil {
  61. b.Fatal(err)
  62. }
  63. b.ResetTimer()
  64. for n := 0; n < b.N; n++ {
  65. _, err = c.VerifyHeaderAtHeight(1000, bTime.Add(1000*time.Minute))
  66. if err != nil {
  67. b.Fatal(err)
  68. }
  69. }
  70. }
  71. func BenchmarkBackwards(b *testing.B) {
  72. trustedHeader, _ := benchmarkFullNode.SignedHeader(0)
  73. c, err := NewClient(
  74. chainID,
  75. TrustOptions{
  76. Period: 24 * time.Hour,
  77. Height: trustedHeader.Height,
  78. Hash: trustedHeader.Hash(),
  79. },
  80. benchmarkFullNode,
  81. []provider.Provider{benchmarkFullNode},
  82. dbs.New(dbm.NewMemDB(), chainID),
  83. Logger(log.TestingLogger()),
  84. )
  85. if err != nil {
  86. b.Fatal(err)
  87. }
  88. b.ResetTimer()
  89. for n := 0; n < b.N; n++ {
  90. _, err = c.VerifyHeaderAtHeight(1, bTime)
  91. if err != nil {
  92. b.Fatal(err)
  93. }
  94. }
  95. }