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.

112 lines
2.5 KiB

  1. package benchmarks
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/tendermint/go-crypto"
  6. "github.com/tendermint/go-wire"
  7. proto "github.com/tendermint/tendermint/benchmarks/proto"
  8. "github.com/tendermint/tendermint/p2p"
  9. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  10. )
  11. func BenchmarkEncodeStatusWire(b *testing.B) {
  12. b.StopTimer()
  13. pubKey := crypto.GenPrivKeyEd25519().PubKey()
  14. status := &ctypes.ResultStatus{
  15. NodeInfo: &p2p.NodeInfo{
  16. PubKey: pubKey,
  17. Moniker: "SOMENAME",
  18. Network: "SOMENAME",
  19. RemoteAddr: "SOMEADDR",
  20. ListenAddr: "SOMEADDR",
  21. Version: "SOMEVER",
  22. Other: []string{"SOMESTRING", "OTHERSTRING"},
  23. },
  24. PubKey: pubKey,
  25. LatestBlockHash: []byte("SOMEBYTES"),
  26. LatestBlockHeight: 123,
  27. LatestBlockTime: time.Unix(0, 1234),
  28. }
  29. b.StartTimer()
  30. counter := 0
  31. for i := 0; i < b.N; i++ {
  32. jsonBytes := wire.JSONBytes(status)
  33. counter += len(jsonBytes)
  34. }
  35. }
  36. func BenchmarkEncodeNodeInfoWire(b *testing.B) {
  37. b.StopTimer()
  38. pubKey := crypto.GenPrivKeyEd25519().PubKey()
  39. nodeInfo := &p2p.NodeInfo{
  40. PubKey: pubKey,
  41. Moniker: "SOMENAME",
  42. Network: "SOMENAME",
  43. RemoteAddr: "SOMEADDR",
  44. ListenAddr: "SOMEADDR",
  45. Version: "SOMEVER",
  46. Other: []string{"SOMESTRING", "OTHERSTRING"},
  47. }
  48. b.StartTimer()
  49. counter := 0
  50. for i := 0; i < b.N; i++ {
  51. jsonBytes := wire.JSONBytes(nodeInfo)
  52. counter += len(jsonBytes)
  53. }
  54. }
  55. func BenchmarkEncodeNodeInfoBinary(b *testing.B) {
  56. b.StopTimer()
  57. pubKey := crypto.GenPrivKeyEd25519().PubKey()
  58. nodeInfo := &p2p.NodeInfo{
  59. PubKey: pubKey,
  60. Moniker: "SOMENAME",
  61. Network: "SOMENAME",
  62. RemoteAddr: "SOMEADDR",
  63. ListenAddr: "SOMEADDR",
  64. Version: "SOMEVER",
  65. Other: []string{"SOMESTRING", "OTHERSTRING"},
  66. }
  67. b.StartTimer()
  68. counter := 0
  69. for i := 0; i < b.N; i++ {
  70. jsonBytes := wire.BinaryBytes(nodeInfo)
  71. counter += len(jsonBytes)
  72. }
  73. }
  74. func BenchmarkEncodeNodeInfoProto(b *testing.B) {
  75. b.StopTimer()
  76. pubKey := crypto.GenPrivKeyEd25519().PubKey().Unwrap().(crypto.PubKeyEd25519)
  77. pubKey2 := &proto.PubKey{Ed25519: &proto.PubKeyEd25519{Bytes: pubKey[:]}}
  78. nodeInfo := &proto.NodeInfo{
  79. PubKey: pubKey2,
  80. Moniker: "SOMENAME",
  81. Network: "SOMENAME",
  82. RemoteAddr: "SOMEADDR",
  83. ListenAddr: "SOMEADDR",
  84. Version: "SOMEVER",
  85. Other: []string{"SOMESTRING", "OTHERSTRING"},
  86. }
  87. b.StartTimer()
  88. counter := 0
  89. for i := 0; i < b.N; i++ {
  90. bytes, err := nodeInfo.Marshal()
  91. if err != nil {
  92. b.Fatal(err)
  93. return
  94. }
  95. //jsonBytes := wire.JSONBytes(nodeInfo)
  96. counter += len(bytes)
  97. }
  98. }