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.

120 lines
2.6 KiB

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