log: add benchmark for handler.Log (#494)

Updates #480
This commit is contained in:
Cuong Manh Le 2021-08-26 17:36:07 +07:00 committed by GitHub
parent f469db94ef
commit 747318b303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

35
log/benchmark_test.go Normal file
View File

@ -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(&ethlog.Record{
Time: time.Now().UTC(),
Lvl: ethlog.LvlCrit,
Msg: "critical error",
KeyNames: ethlog.RecordKeyNames{
Time: timeKey,
Msg: msgKey,
Lvl: lvlKey,
Ctx: ctxKey,
},
})
}
}