From 747318b303a540eea14976991ed4afb87d335c83 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 26 Aug 2021 17:36:07 +0700 Subject: [PATCH] log: add benchmark for handler.Log (#494) Updates #480 --- log/benchmark_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 log/benchmark_test.go diff --git a/log/benchmark_test.go b/log/benchmark_test.go new file mode 100644 index 00000000..cbf0c23c --- /dev/null +++ b/log/benchmark_test.go @@ -0,0 +1,35 @@ +package log + +import ( + "io" + "testing" + + "github.com/cosmos/cosmos-sdk/server" + ethlog "github.com/ethereum/go-ethereum/log" + "github.com/rs/zerolog" + "github.com/tendermint/tendermint/types/time" +) + +func BenchmarkHandler_Log(b *testing.B) { + logger := &server.ZeroLogWrapper{ + Logger: zerolog.New(io.Discard).Level(zerolog.DebugLevel).With().Timestamp().Logger(), + } + h := NewHandler(logger) + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + h.Log(ðlog.Record{ + Time: time.Now().UTC(), + Lvl: ethlog.LvlCrit, + Msg: "critical error", + KeyNames: ethlog.RecordKeyNames{ + Time: timeKey, + Msg: msgKey, + Lvl: lvlKey, + Ctx: ctxKey, + }, + }) + } +}