-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaller_test.go
49 lines (45 loc) · 1013 Bytes
/
caller_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
package bilog
import (
"regexp"
"testing"
)
func TestCallerFeatures(t *testing.T) {
for i := 0; i < 5; i++ {
_, _ = Caller(3)
_, _ = CallerOfCache(3)
_, _ = CallerOfConcurrentCache(3)
}
}
func TestCutString(t *testing.T) {
compile, err := regexp.Compile("bilog[/\\\\]{1,}logger.go")
if err != nil {
t.Error(err)
return
}
if !compile.MatchString(cutFileName("/Users/harder/github.com/nyan233/bilog/logger.go")) {
t.Error("format failed")
}
if !compile.MatchString(cutFileName("\\Users\\github.com\\nyan233\\bilog\\logger.go")) {
t.Error("format failed")
}
}
func BenchmarkCaller(b *testing.B) {
b.Run("Default", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = Caller(3)
}
})
b.Run("CallerCached", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = CallerOfCache(3)
}
})
b.Run("CallerConcurrentCache", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = CallerOfConcurrentCache(3)
}
})
}