-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_test.go
More file actions
78 lines (73 loc) · 1.43 KB
/
engine_test.go
File metadata and controls
78 lines (73 loc) · 1.43 KB
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
package golog
import (
"fmt"
"strings"
"testing"
)
func runUserMessage(log *Logger, num int) func(b *testing.B) {
log = log.Copy()
return func(b *testing.B) {
b.ReportAllocs()
message := strings.Repeat("x", num)
b.ResetTimer()
for range b.N {
log.Info().Send(message)
}
}
}
func runWithModules(log *Logger, num int) func(b *testing.B) {
log = log.Copy()
return func(b *testing.B) {
b.ReportAllocs()
for range num {
log = log.Module(fmt.Sprintf("mod-%d", num))
}
b.ResetTimer()
for range b.N {
log.Info().Send("test")
}
}
}
func runJustMessage(log *Logger) func(b *testing.B) {
log = log.Copy()
return func(b *testing.B) {
b.ReportAllocs()
for range b.N {
log.Info().Send("test")
}
}
}
func runWithDetails(log *Logger) func(b *testing.B) {
log = log.Copy()
return func(b *testing.B) {
b.Run("string", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for range b.N {
log.Info().Details("test").Send("test")
}
})
b.Run("int", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for range b.N {
log.Info().Details(5).Send("test")
}
})
b.Run("float", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for range b.N {
log.Info().Details(3.14).Send("test")
}
})
b.Run("slice", func(b *testing.B) {
b.ReportAllocs()
arr := []int{1, 2, 3, 4, 5}
b.ResetTimer()
for range b.N {
log.Info().Details(arr).Send("test")
}
})
}
}