-
Notifications
You must be signed in to change notification settings - Fork 0
/
clues_benchmark_test.go
276 lines (244 loc) · 5.76 KB
/
clues_benchmark_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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package clues_test
import (
"context"
"math/rand"
"testing"
"github.com/alcionai/clues"
)
var (
benchKeys []int64
benchVals []int64
)
const benchSize = 4096
func init() {
benchKeys, benchVals = make([]int64, benchSize), make([]int64, benchSize)
for i := 0; i < benchSize; i++ {
benchKeys[i], benchVals[i] = rand.Int63(), rand.Int63()
}
rand.Shuffle(benchSize, func(i, j int) {
benchKeys[i], benchKeys[j] = benchKeys[j], benchKeys[i]
})
}
func BenchmarkAdd_singleConstKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", "bar")
}
}
func BenchmarkAdd_singleStaticKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchSize-i, i)
}
}
func BenchmarkAdd_singleConstKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", i)
}
}
func BenchmarkAdd_singleStaticKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, i, "bar")
}
}
func BenchmarkAdd_singleConstKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", benchVals[i%benchSize])
}
}
func BenchmarkAdd_singleRandKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchVals[i%benchSize], "bar")
}
}
func BenchmarkAdd_singleRandKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchVals[i%benchSize], benchVals[i%benchSize])
}
}
func BenchmarkAdd_multConstKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", "bar", "baz", "qux")
}
}
func BenchmarkAdd_multStaticKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchSize-i, i, i-benchSize, i)
}
}
func BenchmarkAdd_multConstKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", i, "baz", -i)
}
}
func BenchmarkAdd_multStaticKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, i, "bar", -i, "qux")
}
}
func BenchmarkAdd_multConstKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(
ctx,
"foo", benchVals[i%benchSize],
"baz", -benchVals[i%benchSize])
}
}
func BenchmarkAdd_multRandKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(
ctx,
benchVals[i%benchSize], "bar",
-benchVals[i%benchSize], "qux")
}
}
func BenchmarkAdd_multRandKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
ctx = clues.Add(
ctx,
benchVals[i%benchSize], benchVals[i%benchSize],
-benchVals[i%benchSize], -benchVals[i%benchSize])
}
}
func BenchmarkAddMap_constKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[string]string{"foo": "bar", "baz": "qux"}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_staticKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[int]int{benchSize - i: i, i - benchSize: i}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_constKStaticV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[string]int{"foo": i, "baz": -i}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_staticKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[int]string{i: "bar", -i: "qux"}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_constKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[string]int64{
"foo": benchVals[i%benchSize],
"baz": -benchVals[i%benchSize],
}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_randKConstV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[int64]string{
benchVals[i%benchSize]: "bar",
-benchVals[i%benchSize]: "qux",
}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkAddMap_randKRandV(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
m := map[int64]int64{
benchVals[i%benchSize]: benchVals[i%benchSize],
-benchVals[i%benchSize]: -benchVals[i%benchSize],
}
ctx = clues.AddMap(ctx, m)
}
}
func BenchmarkIn_constMap(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
m := map[string]any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", "bar")
dn = clues.In(ctx)
m = dn.Map()
}
_ = dn
_ = m
}
func BenchmarkIn_staticMap(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
m := map[string]any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchSize-i, i)
dn = clues.In(ctx)
m = dn.Map()
}
_ = dn
_ = m
}
func BenchmarkIn_randMap(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
m := map[string]any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchVals[i%benchSize], benchVals[i%benchSize])
dn = clues.In(ctx)
m = dn.Map()
}
_ = dn
_ = m
}
func BenchmarkIn_constSlice(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
s := []any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, "foo", "bar")
dn = clues.In(ctx)
s = dn.Slice()
}
_ = dn
_ = s
}
func BenchmarkIn_staticSlice(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
s := []any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchSize-i, i)
dn = clues.In(ctx)
s = dn.Slice()
}
_ = dn
_ = s
}
func BenchmarkIn_randSlice(b *testing.B) {
ctx := context.Background()
dn := clues.In(ctx)
s := []any{}
for i := 0; i < b.N; i++ {
ctx = clues.Add(ctx, benchVals[i%benchSize], benchVals[i%benchSize])
dn = clues.In(ctx)
s = dn.Slice()
}
_ = dn
_ = s
}