-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_bench_test.go
63 lines (45 loc) · 920 Bytes
/
cache_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
59
60
61
62
63
package goche
import (
"bytes"
"testing"
)
func BenchmarkIntegration(b *testing.B) {
data := blob('a', 1024)
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache := New[int, []byte]()
for j := 0; j < 1000; j++ {
cache.Set(j, data)
}
for j := 0; j < 1500; j++ {
cache.Get(j)
}
}
}
func BenchmarkCache_Set(b *testing.B) {
data := blob('a', 1024)
cache := New[string, []byte]()
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Set("foo", data)
}
}
func BenchmarkCache_Get(b *testing.B) {
data := blob('a', 1024)
cache := New[string, []byte]()
cache.items["foo"] = cache.newItem(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Get("foo")
}
}
func BenchmarkCache_Delete(b *testing.B) {
cache := New[string, []byte]()
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Delete("foo")
}
}
func blob(char byte, len int) []byte {
return bytes.Repeat([]byte{char}, len)
}