This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger_bench_test.go
84 lines (74 loc) · 1.6 KB
/
logger_bench_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
package log
import (
"io/ioutil"
"testing"
"time"
"github.com/qingstor/log/level"
)
func benchmarkLogger(b *testing.B, f func(*Logger)) {
tf, _ := NewText(&TextConfig{
TimeFormat: "1136239445",
EntryFormat: "{value}",
})
m := MatchHigherLevel(level.Info)
logger := New().
WithExecutor(ExecuteMatchWrite(m, ioutil.Discard)).
WithTransformer(tf)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
f(logger)
}
})
}
func BenchmarkNew(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = New()
}
})
}
func BenchmarkLogger_NoOutput(b *testing.B) {
now := time.Now()
x := "Hello, world."
benchmarkLogger(b, func(logger *Logger) {
logger.Info(
String("string", x),
Bytes("bytes", []byte(x)),
Int("int64", 1234567890),
Float("float64", 1234.056789),
Time("time", now, time.RFC1123),
)
})
}
func BenchmarkLogger_Info(b *testing.B) {
now := time.Now()
x := "Hello, world."
benchmarkLogger(b, func(logger *Logger) {
logger.Error(
String("string", x),
Bytes("bytes", []byte(x)),
Int("int64", 1234567890),
Float("float64", 1234.056789),
Time("time", now, time.RFC1123),
)
})
}
func BenchmarkLogger_Int(b *testing.B) {
benchmarkLogger(b, func(logger *Logger) {
logger.Error(
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
Int("int64", 1234567890),
)
})
}