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.

110 lines
2.5 KiB

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