test: add bench

master
Evan Chen 2021-11-05 15:46:23 +08:00
parent f5a1ba9c18
commit 291341b6ad
1 changed files with 51 additions and 0 deletions

View File

@ -152,3 +152,54 @@ func TestDefaultLogger(t *testing.T) {
l.Warn("TestDefaultLogger")
l.Info("TestDefaultLogger")
}
func BenchmarkDefault(b *testing.B) {
SetErrOutput(io.Discard)
SetOutput(io.Discard)
Reload()
LEVEL = 15
for i := 0; i < b.N; i++ {
PROD = true
Error("err in", "BenchmarkDefault: ", i)
ErrorF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
Debug("err in", "BenchmarkDefault: ", i)
DebugF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
Warn("err in", "BenchmarkDefault: ", i)
WarnF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
}
for i := 0; i < b.N; i++ {
PROD = false
Error("err in", "BenchmarkDefault: ", i)
ErrorF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
Debug("err in", "BenchmarkDefault: ", i)
DebugF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
Warn("err in", "BenchmarkDefault: ", i)
WarnF(H{"test": "fields"}, "err in", "BenchmarkDefault: ", i)
}
}
func BenchmarkSub1(b *testing.B) {
LEVEL = 15
l := Sub("Sub1")
l.SetErrOutput(io.Discard)
l.SetOutput(io.Discard)
l.Reload()
for i := 0; i < b.N; i++ {
PROD = true
l.Error("err in", "BenchmarkDefault: ", i)
l.ErrorF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
l.Debug("err in", "BenchmarkDefault: ", i)
l.DebugF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
l.Warn("err in", "BenchmarkDefault: ", i)
l.WarnF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
}
for i := 0; i < b.N; i++ {
PROD = false
l.Error("err in", "BenchmarkDefault: ", i)
l.ErrorF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
l.Debug("err in", "BenchmarkDefault: ", i)
l.DebugF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
l.Warn("err in", "BenchmarkDefault: ", i)
l.WarnF(H{"test": "fields"}, "err in", "BenchmarkSub1: ", i)
}
}