Browse Source

Add logger benchmark

tags/v1.1.0
David Bariod 1 year ago
parent
commit
d3162770a8
1 changed files with 24 additions and 0 deletions
  1. 24
    0
      logger_bench_test.go

+ 24
- 0
logger_bench_test.go View File

@@ -1,6 +1,7 @@
1 1
 package logrus
2 2
 
3 3
 import (
4
+	"io/ioutil"
4 5
 	"os"
5 6
 	"testing"
6 7
 )
@@ -59,3 +60,26 @@ func doLoggerBenchmarkNoLock(b *testing.B, out *os.File, formatter Formatter, fi
59 60
 		}
60 61
 	})
61 62
 }
63
+
64
+func BenchmarkLoggerJSONFormatter(b *testing.B) {
65
+	doLoggerBenchmarkWithFormatter(b, &JSONFormatter{})
66
+}
67
+
68
+func BenchmarkLoggerTextFormatter(b *testing.B) {
69
+	doLoggerBenchmarkWithFormatter(b, &TextFormatter{})
70
+}
71
+
72
+func doLoggerBenchmarkWithFormatter(b *testing.B, f Formatter) {
73
+	b.SetParallelism(100)
74
+	log := New()
75
+	log.Formatter = f
76
+	log.Out = ioutil.Discard
77
+	b.RunParallel(func(pb *testing.PB) {
78
+		for pb.Next() {
79
+			log.
80
+				WithField("foo1", "bar1").
81
+				WithField("foo2", "bar2").
82
+				Info("this is a dummy log")
83
+		}
84
+	})
85
+}

Loading…
Cancel
Save