-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
55 lines (45 loc) · 955 Bytes
/
main.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
package main
import (
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/jamiealquiza/bicache/v2"
"github.com/jamiealquiza/tachymeter"
)
func main() {
c, _ := bicache.New(&bicache.Config{
MFUSize: 50000,
MRUSize: 50000,
AutoEvict: 1000,
ShardCount: 512,
})
keys := 100000
// Cache pre-warm.
for i := 0; i < keys; i++ {
key := strconv.Itoa(i)
c.Set(key, []byte{0})
}
t := tachymeter.New(&tachymeter.Config{Size: keys})
fmt.Printf("[ Set %d keys ]\n", keys)
for i := 0; i < keys; i++ {
key := strconv.Itoa(i)
start := time.Now()
c.Set(key, []byte{0})
t.AddTime(time.Since(start))
}
fmt.Println(t.Calc())
fmt.Println()
t.Reset()
fmt.Printf("[ Get %d keys ]\n", keys)
for i := 0; i < keys; i++ {
key := strconv.Itoa(i)
start := time.Now()
_ = c.Get(key)
t.AddTime(time.Since(start))
}
fmt.Println(t.Calc())
stats := c.Stats()
j, _ := json.Marshal(stats)
fmt.Printf("\n%s\n", string(j))
}