/
main_test.go
107 lines (96 loc) · 2.45 KB
/
main_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package lru
import (
"github.com/golang/groupcache/lru"
"strconv"
"testing"
)
const (
lruSize = 10000
)
func BenchmarkGetPLRU(b *testing.B) {
plru := NewPreparedLRU()
plru.setMaxStmts(lruSize)
for i := 0; i < lruSize; i++ {
plru.set("A", strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.get("A", strconv.FormatInt(int64(n), 10))
}
}
func BenchmarkGetLLRU(b *testing.B) {
plru := NewListLRU()
plru.setMaxStmts(lruSize)
for i := 0; i < lruSize; i++ {
plru.set("A", strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.get("A", strconv.FormatInt(int64(n), 10))
}
}
func BenchmarkGetGPLRU(b *testing.B) {
plru := lru.New(lruSize)
for i := 0; i < lruSize; i++ {
plru.Add("A"+strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.Get("A" + strconv.FormatInt(int64(n), 10))
}
}
func BenchmarkNotSequentialPLRU(b *testing.B) {
plru := NewPreparedLRU()
plru.setMaxStmts(lruSize)
for i := 0; i < lruSize; i++ {
plru.set("A", strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 1; n <= b.N; n++ {
plru.get("A", strconv.FormatInt(int64(lruSize%n), 10))
}
}
func BenchmarkNotSequentialLLRU(b *testing.B) {
plru := NewListLRU()
plru.setMaxStmts(lruSize)
for i := 0; i < lruSize; i++ {
plru.set("A", strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 1; n <= b.N; n++ {
plru.get("A", strconv.FormatInt(int64(lruSize%n), 10))
}
}
func BenchmarkNotSequentialGPLRU(b *testing.B) {
plru := lru.New(lruSize)
for i := 0; i < lruSize; i++ {
plru.Add("A"+strconv.FormatInt(int64(i), 10), "A")
}
// run the Fib function b.N times
for n := 1; n <= b.N; n++ {
plru.Get("A" + strconv.FormatInt(int64(lruSize%n), 10))
}
}
func BenchmarkSetPLRU(b *testing.B) {
plru := NewPreparedLRU()
plru.setMaxStmts(lruSize)
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.set("A", strconv.FormatInt(int64(n), 10), "A")
}
}
func BenchmarkSetLLRU(b *testing.B) {
plru := NewListLRU()
plru.setMaxStmts(lruSize)
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.set("A", strconv.FormatInt(int64(n), 10), "A")
}
}
func BenchmarkSetGPLRU(b *testing.B) {
plru := lru.New(lruSize)
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
plru.Add("A"+strconv.FormatInt(int64(n), 10), "A")
}
}