-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging_test.go
More file actions
47 lines (41 loc) · 896 Bytes
/
Copy pathlogging_test.go
File metadata and controls
47 lines (41 loc) · 896 Bytes
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
package main
import (
"math/rand"
"testing"
)
func BenchmarkLogSafeSlice(b *testing.B) {
lrgStr := make([]string, 0, 10000)
lrgInt := make([]int, 0, 10000)
lrgMap := make(map[string]int, 10000)
for i := 0; i < 10000; i++ {
x := rand.Int()
y := randString(15)
lrgInt = append(lrgInt, x)
lrgStr = append(lrgStr, y)
lrgMap[y] = x
}
tests := []struct {
name string
args interface{}
}{
{name: "string slice", args: lrgStr},
{name: "int slice", args: lrgInt},
{name: "single string", args: "Hello, world"},
{name: "single int", args: 15},
{name: "large map", args: lrgMap},
}
for _, tt := range tests {
b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
LogSafeSlice(tt.args)
}
})
}
}
func randString(len int) string {
if len == 0 {
return ""
}
ascii := rune(97) + rune(rand.Intn(26))
return string(ascii) + randString(len-1)
}