forked from jorenkoyen/go-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
89 lines (80 loc) · 1.77 KB
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package logger
import (
"io"
"testing"
)
var (
fakeMessage = "Test logging, but use a somewhat realistic message length."
)
func BenchmarkLogEmpty(b *testing.B) {
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("")
}
})
}
func BenchmarkDisabled(b *testing.B) {
logger := New(io.Discard)
logger.SetLogLevel(LevelFatal)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Debug(fakeMessage)
}
})
}
func BenchmarkInfo(b *testing.B) {
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info(fakeMessage)
}
})
}
func BenchmarkFormatted(b *testing.B) {
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
// bool: %t
// int, int8 etc.: %d
// float32: %g
// string: %s
logger.Infof("bool=%t int=%d float=%g string=%s", true, 100, 22.23, "hello")
}
})
}
func BenchmarkPrettyFormatter(b *testing.B) {
formatter := NewPrettyFormatter()
logger := NewWithOptions(Options{Writer: io.Discard, Formatter: formatter})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("Hello world!")
}
})
}
func BenchmarkPrettyFormatterWithCallerSource(b *testing.B) {
formatter := NewPrettyFormatter()
formatter.AppendSource = true
logger := NewWithOptions(Options{Writer: io.Discard, Formatter: formatter})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("Hello world!")
}
})
}
func BenchmarkLoggerNew(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger := New(io.Discard)
if logger == nil {
b.Fatal("unable to create logger")
}
}
})
}