From 34d6d7b90e453db5d2f6615f8bec5b34814bbe06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Mon, 14 Jun 2021 07:50:44 +0800 Subject: [PATCH] add log filter benchmark --- log/filter_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/log/filter_test.go b/log/filter_test.go index 529d87331..25a4bd27a 100644 --- a/log/filter_test.go +++ b/log/filter_test.go @@ -1,6 +1,7 @@ package log import ( + "io/ioutil" "testing" ) @@ -32,7 +33,7 @@ func TestFilterCaller(t *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewFilter(logger) log.Log(LevelDebug, "msg1", "te1st debug") - logHelper := NewHelper(NewFilter(NewFilter(logger))) + logHelper := NewHelper(NewFilter(logger)) logHelper.Log(LevelDebug, "msg1", "te1st debug") } @@ -55,6 +56,27 @@ func TestFilterFunc(t *testing.T) { log.Infow("password", "123456") } +func BenchmarkFilterKeys(b *testing.B) { + log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterKeys("password"))) + for i := 0; i < b.N; i++ { + log.Infow("password", "123456") + } +} + +func BenchmarkFilterValues(b *testing.B) { + log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterValues("password"))) + for i := 0; i < b.N; i++ { + log.Infow("password") + } +} + +func BenchmarkFilterHook(b *testing.B) { + log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterHook(testFilterFunc))) + for i := 0; i < b.N; i++ { + log.Info("password","123456") + } +} + func testFilterFunc(level Level, keyvals ...interface{}) bool { if level == LevelWarn { return true