-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_bench_test.go
101 lines (91 loc) · 2.22 KB
/
text_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package log_test
import (
"context"
"io/ioutil"
nativeLog "log"
"testing"
"github.com/tryfix/log"
)
const testLog = `test log entry, test log entry, test log entry, test log entry, test log entry`
func BenchmarkGoNative(b *testing.B) {
lg := nativeLog.New(ioutil.Discard, `test-logger.path`, nativeLog.Lmicroseconds)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.Println(testLog)
}
})
}
func BenchmarkTextLogInfo(b *testing.B) {
lg := log.NewLog(
log.WithLevel(log.INFO),
log.WithStdOut(ioutil.Discard),
log.WithFilePath(false),
log.WithColors(false)).Log()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.Info(testLog)
}
})
}
func BenchmarkTextLogInfoFilePath(b *testing.B) {
lg := log.NewLog(
log.WithLevel(log.INFO),
log.WithStdOut(ioutil.Discard),
log.WithFilePath(true),
log.WithColors(false)).Log()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.Info(testLog)
}
})
}
func BenchmarkTextInfoContext(b *testing.B) {
lg := log.NewLog(
log.WithLevel(log.INFO),
log.WithStdOut(ioutil.Discard),
log.WithFilePath(false),
log.WithColors(false)).Log()
ctx := context.Background()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.InfoContext(ctx, testLog)
}
})
}
func BenchmarkTextInfoContextExt(b *testing.B) {
ctx1 := context.WithValue(context.Background(), `ctx1`, `ctx one value`)
ctx2 := context.WithValue(ctx1, `ctx2`, `ctx two value`)
lg := log.NewLog(
log.WithLevel(log.INFO),
log.WithStdOut(ioutil.Discard),
log.WithFilePath(false),
log.WithCtxExtractor(func(ctx context.Context) []interface{} {
return []interface{}{ctx.Value(`ctx1`), ctx.Value(`ctx2`)}
}),
log.WithColors(false)).Log()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.InfoContext(ctx2, testLog)
}
})
}
func BenchmarkTextInfoParams(b *testing.B) {
lg := log.NewLog(
log.WithLevel(log.INFO),
log.WithStdOut(ioutil.Discard),
log.WithFilePath(false),
log.WithColors(false)).Log()
ctx := context.Background()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
lg.InfoContext(ctx, testLog,
`parm1`, `parm2`, `parm3`, `parm4`)
}
})
}