forked from valyala/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userdata_timing_test.go
48 lines (44 loc) · 950 Bytes
/
userdata_timing_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
package fasthttp
import (
"testing"
)
func BenchmarkUserDataCustom(b *testing.B) {
keys := []string{"foobar", "baz", "aaa", "bsdfs"}
b.RunParallel(func(pb *testing.PB) {
var u userData
var v interface{} = u
for pb.Next() {
for _, key := range keys {
u.Set(key, v)
}
for _, key := range keys {
vv := u.Get(key)
if _, ok := vv.(userData); !ok {
b.Fatalf("unexpected value %v for key %q", vv, key)
}
}
u.Reset()
}
})
}
func BenchmarkUserDataStdMap(b *testing.B) {
keys := []string{"foobar", "baz", "aaa", "bsdfs"}
b.RunParallel(func(pb *testing.PB) {
u := make(map[string]interface{})
var v interface{} = u
for pb.Next() {
for _, key := range keys {
u[key] = v
}
for _, key := range keys {
vv := u[key]
if _, ok := vv.(map[string]interface{}); !ok {
b.Fatalf("unexpected value %v for key %q", vv, key)
}
}
for k := range u {
delete(u, k)
}
}
})
}