-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzipf_test.go
65 lines (57 loc) · 1.18 KB
/
zipf_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
package traces
import (
"os"
"testing"
)
func TestRequestZipf(t *testing.T) {
for _, p := range policies {
p := p
t.Run(p, func(t *testing.T) {
t.Parallel()
testRequestZipf(t, p, "request_zipf-"+p+".txt")
})
}
}
func testRequestZipf(t *testing.T, policy, reportFile string) {
opt := options{
policy: policy,
cacheSize: 512,
reportInterval: 1000,
maxItems: 100000,
}
provider := NewZipfProvider(1.01, opt.maxItems)
w, err := os.Create(reportFile)
if err != nil {
t.Fatal(err)
}
defer w.Close()
reporter := NewReporter(w)
benchmarkCache(provider, reporter, opt)
}
func TestSizeZipf(t *testing.T) {
for _, p := range policies {
p := p
t.Run(p, func(t *testing.T) {
t.Parallel()
testSizeZipf(t, p, "size_zipf-"+p+".txt")
})
}
}
func testSizeZipf(t *testing.T, policy, reportFile string) {
opt := options{
cacheSize: 250,
policy: policy,
maxItems: 100000,
}
w, err := os.Create(reportFile)
if err != nil {
t.Fatal(err)
}
defer w.Close()
reporter := NewReporter(w)
for i := 0; i < 5; i++ {
provider := NewZipfProvider(1.01, opt.maxItems)
benchmarkCache(provider, reporter, opt)
opt.cacheSize += opt.cacheSize
}
}