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.

108 lines
2.4 KiB

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-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. ListenAddr: "SOMEADDR",
  20. Version: "SOMEVER",
  21. Other: []string{"SOMESTRING", "OTHERSTRING"},
  22. },
  23. PubKey: pubKey,
  24. LatestBlockHash: []byte("SOMEBYTES"),
  25. LatestBlockHeight: 123,
  26. LatestBlockTime: time.Unix(0, 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()
  38. nodeInfo := p2p.NodeInfo{
  39. PubKey: pubKey,
  40. Moniker: "SOMENAME",
  41. Network: "SOMENAME",
  42. ListenAddr: "SOMEADDR",
  43. Version: "SOMEVER",
  44. Other: []string{"SOMESTRING", "OTHERSTRING"},
  45. }
  46. b.StartTimer()
  47. counter := 0
  48. for i := 0; i < b.N; i++ {
  49. jsonBytes := wire.JSONBytes(nodeInfo)
  50. counter += len(jsonBytes)
  51. }
  52. }
  53. func BenchmarkEncodeNodeInfoBinary(b *testing.B) {
  54. b.StopTimer()
  55. pubKey := crypto.GenPrivKeyEd25519().PubKey()
  56. nodeInfo := p2p.NodeInfo{
  57. PubKey: pubKey,
  58. Moniker: "SOMENAME",
  59. Network: "SOMENAME",
  60. ListenAddr: "SOMEADDR",
  61. Version: "SOMEVER",
  62. Other: []string{"SOMESTRING", "OTHERSTRING"},
  63. }
  64. b.StartTimer()
  65. counter := 0
  66. for i := 0; i < b.N; i++ {
  67. jsonBytes := wire.BinaryBytes(nodeInfo)
  68. counter += len(jsonBytes)
  69. }
  70. }
  71. func BenchmarkEncodeNodeInfoProto(b *testing.B) {
  72. b.StopTimer()
  73. pubKey := crypto.GenPrivKeyEd25519().PubKey().Unwrap().(crypto.PubKeyEd25519)
  74. pubKey2 := &proto.PubKey{Ed25519: &proto.PubKeyEd25519{Bytes: pubKey[:]}}
  75. nodeInfo := proto.NodeInfo{
  76. PubKey: pubKey2,
  77. Moniker: "SOMENAME",
  78. Network: "SOMENAME",
  79. ListenAddr: "SOMEADDR",
  80. Version: "SOMEVER",
  81. Other: []string{"SOMESTRING", "OTHERSTRING"},
  82. }
  83. b.StartTimer()
  84. counter := 0
  85. for i := 0; i < b.N; i++ {
  86. bytes, err := nodeInfo.Marshal()
  87. if err != nil {
  88. b.Fatal(err)
  89. return
  90. }
  91. //jsonBytes := wire.JSONBytes(nodeInfo)
  92. counter += len(bytes)
  93. }
  94. }