forked from go-redis/cache
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench_test.go
58 lines (50 loc) · 972 Bytes
/
bench_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
package cache_test
import (
"strings"
"testing"
"github.com/go-redis/cache/v8"
)
func BenchmarkOnce(b *testing.B) {
mycache := newCacheWithLocal(newRing())
obj := &Object{
Str: strings.Repeat("my very large string", 10),
Num: 42,
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var dst Object
err := mycache.Once(&cache.Item{
Key: "bench-once",
Value: &dst,
Do: func(*cache.Item) (interface{}, error) {
return obj, nil
},
})
if err != nil {
b.Fatal(err)
}
if dst.Num != 42 {
b.Fatalf("%d != 42", dst.Num)
}
}
})
}
func BenchmarkSet(b *testing.B) {
mycache := newCacheWithLocal(newRing())
obj := &Object{
Str: strings.Repeat("my very large string", 10),
Num: 42,
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if err := mycache.Set(&cache.Item{
Key: "bench-set",
Value: obj,
}); err != nil {
b.Fatal(err)
}
}
})
}