diff --git a/benchmarks/simu/counter.go b/benchmarks/simu/counter.go index 8b1b3e5e..8191e8de 100644 --- a/benchmarks/simu/counter.go +++ b/benchmarks/simu/counter.go @@ -22,22 +22,25 @@ func main() { // Read a bunch of responses go func() { for { - res, ok := <-ws.ResultsCh + _, ok := <-ws.ResultsCh if !ok { break } - fmt.Println("Received response", res) + //fmt.Println("Received response", string(wire.JSONBytes(res))) } }() // Make a bunch of requests - request := rpctypes.NewRPCRequest("fakeid", "status", nil) + request := rpctypes.NewRPCRequest("fakeid", "net_info", nil) for i := 0; ; i++ { reqBytes := wire.JSONBytes(request) err := ws.WriteMessage(websocket.TextMessage, reqBytes) if err != nil { Exit(err.Error()) } + if i%1000 == 0 { + fmt.Println(i) + } } ws.Stop() diff --git a/benchmarks/wire_test.go b/benchmarks/wire_test.go new file mode 100644 index 00000000..7da8a7f7 --- /dev/null +++ b/benchmarks/wire_test.go @@ -0,0 +1,60 @@ +package benchmarks + +import ( + "testing" + + "github.com/tendermint/go-crypto" + "github.com/tendermint/go-p2p" + "github.com/tendermint/go-wire" + ctypes "github.com/tendermint/tendermint/rpc/core/types" +) + +func BenchmarkEncodeStatus(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + status := &ctypes.ResultStatus{ + NodeInfo: &p2p.NodeInfo{ + PubKey: pubKey, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + }, + PubKey: pubKey, + LatestBlockHash: []byte("SOMEBYTES"), + LatestBlockHeight: 123, + LatestBlockTime: 1234, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + jsonBytes := wire.JSONBytes(status) + counter += len(jsonBytes) + } + +} + +func BenchmarkEncodeNodeInfo(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + nodeInfo := &p2p.NodeInfo{ + PubKey: pubKey, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + jsonBytes := wire.JSONBytes(nodeInfo) + counter += len(jsonBytes) + } + +}