diff --git a/log_test.go b/log_test.go index ba177ec..a82cbab 100644 --- a/log_test.go +++ b/log_test.go @@ -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) + } +}