Skip to content

Commit f0444d7

Browse files
joeybloggsjoeybloggs
authored andcommitted
add log15 and logrus to benchmarks
1 parent e434ce9 commit f0444d7

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

benchmarks/benchmark_test.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"testing"
88
"time"
99

10+
"gopkg.in/inconshreveable/log15.v2"
11+
12+
"github.com/Sirupsen/logrus"
1013
"github.com/go-playground/log"
1114
"github.com/go-playground/log/handlers/console"
1215
)
@@ -59,11 +62,16 @@ func TestMain(m *testing.M) {
5962

6063
log.RegisterHandler(cLog, log.AllLevels...)
6164

65+
logrus.SetFormatter(&logrus.TextFormatter{})
66+
logrus.SetOutput(ioutil.Discard)
67+
logrus.SetLevel(logrus.InfoLevel)
68+
6269
os.Exit(m.Run())
6370
}
6471

65-
func BenchmarkConsoleParallel(b *testing.B) {
72+
func BenchmarkConsoleTenFieldsParallel(b *testing.B) {
6673

74+
b.ResetTimer()
6775
// log setup in TestMain
6876
b.RunParallel(func(pb *testing.PB) {
6977
for pb.Next() {
@@ -86,6 +94,7 @@ func BenchmarkConsoleParallel(b *testing.B) {
8694

8795
func BenchmarkConsoleSimpleFieldsParallel(b *testing.B) {
8896

97+
b.ResetTimer()
8998
// log setup in TestMain
9099
b.RunParallel(func(pb *testing.PB) {
91100
for pb.Next() {
@@ -94,3 +103,67 @@ func BenchmarkConsoleSimpleFieldsParallel(b *testing.B) {
94103

95104
})
96105
}
106+
107+
func BenchmarkLogrusText10Fields(b *testing.B) {
108+
109+
b.ResetTimer()
110+
b.RunParallel(func(pb *testing.PB) {
111+
for pb.Next() {
112+
logrus.WithFields(logrus.Fields{
113+
"int": 1,
114+
"int64": int64(1),
115+
"float": 3.0,
116+
"string": "four!",
117+
"bool": true,
118+
"time": time.Unix(0, 0),
119+
"error": errExample.Error(),
120+
"duration": time.Second,
121+
"user-defined type": _jane,
122+
"another string": "done!",
123+
}).Info("Go fast.")
124+
}
125+
})
126+
}
127+
128+
func BenchmarkLogrusTextSimple(b *testing.B) {
129+
130+
b.ResetTimer()
131+
b.RunParallel(func(pb *testing.PB) {
132+
for pb.Next() {
133+
logrus.Info("Go fast.")
134+
}
135+
})
136+
}
137+
138+
func BenchmarkLog1510Fields(b *testing.B) {
139+
logger := log15.New()
140+
logger.SetHandler(log15.StreamHandler(ioutil.Discard, log15.TerminalFormat()))
141+
b.ResetTimer()
142+
b.RunParallel(func(pb *testing.PB) {
143+
for pb.Next() {
144+
logger.Info("Go fast.",
145+
"int", 1,
146+
"int64", int64(1),
147+
"float", 3.0,
148+
"string", "four!",
149+
"bool", true,
150+
"time", time.Unix(0, 0),
151+
"error", errExample.Error(),
152+
"duration", time.Second,
153+
"user-defined type", _jane,
154+
"another string", "done!",
155+
)
156+
}
157+
})
158+
}
159+
160+
func BenchmarkLog15Simple(b *testing.B) {
161+
logger := log15.New()
162+
logger.SetHandler(log15.StreamHandler(ioutil.Discard, log15.TerminalFormat()))
163+
b.ResetTimer()
164+
b.RunParallel(func(pb *testing.PB) {
165+
for pb.Next() {
166+
logger.Info("Go fast.")
167+
}
168+
})
169+
}

0 commit comments

Comments
 (0)