-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_test.go
More file actions
161 lines (143 loc) · 3.24 KB
/
bench_test.go
File metadata and controls
161 lines (143 loc) · 3.24 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package stepmark
import (
"context"
"fmt"
"testing"
)
func BenchmarkEnabled_Disabled(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
Enabled(ctx)
}
}
func BenchmarkEnabled_Enabled(b *testing.B) {
ctx := New(context.Background())
b.ReportAllocs()
for b.Loop() {
Enabled(ctx)
}
}
func BenchmarkRecord_Disabled(b *testing.B) {
ctx := context.Background()
meta := map[string]any{"key": "value"}
b.ReportAllocs()
for b.Loop() {
Record(ctx, "stage", "action", meta)
}
}
func BenchmarkRecord_Enabled(b *testing.B) {
ctx := New(context.Background())
meta := map[string]any{"key": "value"}
b.ReportAllocs()
for b.Loop() {
Record(ctx, "stage", "action", meta)
}
}
func BenchmarkRecordEntity_Disabled(b *testing.B) {
ctx := context.Background()
meta := map[string]any{"key": "value"}
b.ReportAllocs()
for b.Loop() {
RecordEntity(ctx, "entity_1", "stage", "action", meta)
}
}
func BenchmarkRecordEntity_Enabled(b *testing.B) {
ctx := New(context.Background())
meta := map[string]any{"key": "value"}
b.ReportAllocs()
for b.Loop() {
RecordEntity(ctx, fmt.Sprintf("entity_%d", b.N%100), "stage", "action", meta)
}
}
func BenchmarkTrack_Disabled(b *testing.B) {
ctx := context.Background()
meta := map[string]any{"key": "value"}
b.ReportAllocs()
for b.Loop() {
Track(ctx, "entity_1", meta)
}
}
func BenchmarkCollect(b *testing.B) {
ctx := New(context.Background())
for i := 0; i < 50; i++ {
id := fmt.Sprintf("entity_%d", i)
Track(ctx, id, map[string]any{"i": i})
RecordEntity(ctx, id, "stage", "action", nil)
}
for i := 0; i < 10; i++ {
Record(ctx, "stage", "action", map[string]any{"i": i})
}
b.ReportAllocs()
b.ResetTimer()
for b.Loop() {
Collect(ctx)
}
}
func BenchmarkRecord_Disabled_NilMeta(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
Record(ctx, "stage", "action", nil)
}
}
func BenchmarkRecordEntity_Disabled_NilMeta(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
RecordEntity(ctx, "entity_1", "stage", "action", nil)
}
}
func BenchmarkStep_Disabled(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
Step(ctx, "action", nil)
}
}
func BenchmarkStep_Enabled(b *testing.B) {
ctx := New(context.Background())
b.ReportAllocs()
for b.Loop() {
Step(ctx, "action", nil)
}
}
func BenchmarkStepEntity_Disabled(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
StepEntity(ctx, "entity_1", "action", nil)
}
}
func BenchmarkEnter_Disabled(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
Enter(ctx, nil)()
}
}
func BenchmarkEnterEntity_Disabled(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for b.Loop() {
EnterEntity(ctx, "entity_1", nil)()
}
}
func BenchmarkRecordEntity_Filtered(b *testing.B) {
ctx := New(context.Background(), WithEntityFilter(func(id string) bool {
return id == "wanted"
}))
b.ReportAllocs()
for b.Loop() {
RecordEntity(ctx, "blocked", "stage", "action", nil)
}
}
func BenchmarkStepEntity_Filtered(b *testing.B) {
ctx := New(context.Background(), WithEntityFilter(func(id string) bool {
return id == "wanted"
}))
b.ReportAllocs()
for b.Loop() {
StepEntity(ctx, "blocked", "action", nil)
}
}