-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbigcache_storage_bench_test.go
58 lines (51 loc) · 1.32 KB
/
bigcache_storage_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 mgcache
import (
"fmt"
"github.com/allegro/bigcache/v3"
"math"
"testing"
"time"
)
func BenchmarkBigcacheSet_Bytes(b *testing.B) {
client, _ := bigcache.NewBigCache(bigcache.DefaultConfig(5 * time.Minute))
store := NewBigCacheStorage(client, nil)
for k := 0.; k <= 10; k++ {
n := int(math.Pow(2, k))
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
for i := 0; i < b.N*n; i++ {
key := fmt.Sprintf("key-%d", n)
value := []byte(fmt.Sprintf("value-%d", n))
_ = store.Set(key, value)
}
})
}
}
func BenchmarkBigcacheGetBytes(b *testing.B) {
client, _ := bigcache.NewBigCache(bigcache.DefaultConfig(5 * time.Minute))
store := NewBigCacheStorage(client, nil)
key := "test"
_ = store.Set(key, []byte("value"))
for k := 0.; k <= 10; k++ {
n := int(math.Pow(2, k))
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
for i := 0; i < b.N*n; i++ {
_, _ = store.GetBytes(key)
}
})
}
}
func BenchmarkBigcacheGet(b *testing.B) {
client, _ := bigcache.NewBigCache(bigcache.DefaultConfig(5 * time.Minute))
store := NewBigCacheStorage(client, nil)
key := "test"
_ = store.Set(key, []byte("value"))
var value []byte
for k := 0.; k <= 10; k++ {
n := int(math.Pow(2, k))
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
for i := 0; i < b.N*n; i++ {
_ = store.Get(key, &value)
}
})
}
}