-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebugger_test.go
135 lines (111 loc) · 2.16 KB
/
debugger_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Important! Run tests/benchmarks with -tags=debugger
// to include the actual labeling code
package debugger_test
import (
"strconv"
"testing"
"github.com/dlsniper/debugger"
)
var result int
func workerWithout(n int) int {
if n != 1 {
return n + workerWithout(n-1)
}
return 1
}
func workerWithOne(n int) int {
debugger.SetLabels(func() []string {
return []string{
"label1", "label1value",
}
})
if n != 1 {
return n + workerWithOne(n-1)
}
return 1
}
func workerWithThree(n int) int {
debugger.SetLabels(func() []string {
return []string{
"label1", "label1value",
"label2", "label2value",
"label3", "label3value",
}
})
if n != 1 {
return n + workerWithThree(n-1)
}
return 1
}
func workerWithTen(n int) int {
debugger.SetLabels(func() []string {
return []string{
"label1", "label1value",
"label2", "label2value",
"label3", "label3value",
"label4", "label41value",
"label5", "label5value",
"label6", "label6value",
"label7", "label7value",
"label8", "label8value",
"label9", "label9value",
"label10", "label10value",
}
})
if n != 1 {
return n + workerWithTen(n-1)
}
return 1
}
func workerWithConv(n int) int {
debugger.SetLabels(func() []string {
return []string{
"label1", "label1value",
"label2", "label2value",
"label3", strconv.Itoa(n),
}
})
if n != 1 {
return n + workerWithConv(n-1)
}
return 1
}
func BenchmarkWorkerWithout(b *testing.B) {
var res int
for i := 0; i < b.N; i++ {
res = workerWithout(100)
}
result = res
}
func BenchmarkWorkerWithOne(b *testing.B) {
var res int
for i := 0; i < b.N; i++ {
res = workerWithOne(100)
}
result = res
}
func BenchmarkWorkerWithThree(b *testing.B) {
var res int
for i := 0; i < b.N; i++ {
res = workerWithThree(100)
}
result = res
}
func BenchmarkWorkerWithTen(b *testing.B) {
var res int
for i := 0; i < b.N; i++ {
res = workerWithTen(100)
}
result = res
}
func BenchmarkWorkerWithConv(b *testing.B) {
var res int
for i := 0; i < b.N; i++ {
res = workerWithConv(100)
}
result = res
}
func init() {
// force Go to include our variable in the results and not optimize any code based on it
println(result)
}