git » debian:golang-blitiri-go-log » commit 577ccb2

test: Add basic benchmarks

author Alberto Bertogli
2020-05-22 16:25:15 UTC
committer Alberto Bertogli
2020-05-22 16:53:56 UTC
parent 7d576e76b9c51ca5d649d6507d7e367946ad0355

test: Add basic benchmarks

This patch adds two basic benchmarks: one for a call below the current
level, and another one for a normal Infof.

They can be useful to evaluate performance impact of changes.

log_test.go +18 -0

diff --git a/log_test.go b/log_test.go
index 1ce9883..799ada8 100644
--- a/log_test.go
+++ b/log_test.go
@@ -191,3 +191,21 @@ func TestReopenNull(t *testing.T) {
 		t.Errorf("reopen: %v", err)
 	}
 }
+
+// Benchmark a call below the verbosity level.
+func BenchmarkDebugf(b *testing.B) {
+	l := New(nopCloser{ioutil.Discard})
+	defer l.Close()
+	for i := 0; i < b.N; i++ {
+		l.Debugf("test %d", i)
+	}
+}
+
+// Benchmark a normal call.
+func BenchmarkInfof(b *testing.B) {
+	l := New(nopCloser{ioutil.Discard})
+	defer l.Close()
+	for i := 0; i < b.N; i++ {
+		l.Infof("test %d", i)
+	}
+}