forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lru_cache_benchmark_test.go
62 lines (56 loc) · 1.13 KB
/
lru_cache_benchmark_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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package cache
import (
"crypto/rand"
"testing"
"github.com/ava-labs/avalanchego/ids"
)
func BenchmarkLRUCachePutSmall(b *testing.B) {
smallLen := 5
cache := &LRU{Size: smallLen}
for n := 0; n < b.N; n++ {
for i := 0; i < smallLen; i++ {
var id ids.ID
if _, err := rand.Read(id[:]); err != nil {
b.Fatal(err)
}
cache.Put(id, n)
}
b.StopTimer()
cache.Flush()
b.StartTimer()
}
}
func BenchmarkLRUCachePutMedium(b *testing.B) {
mediumLen := 250
cache := &LRU{Size: mediumLen}
for n := 0; n < b.N; n++ {
for i := 0; i < mediumLen; i++ {
var id ids.ID
if _, err := rand.Read(id[:]); err != nil {
b.Fatal(err)
}
cache.Put(id, n)
}
b.StopTimer()
cache.Flush()
b.StartTimer()
}
}
func BenchmarkLRUCachePutLarge(b *testing.B) {
largeLen := 10000
cache := &LRU{Size: largeLen}
for n := 0; n < b.N; n++ {
for i := 0; i < largeLen; i++ {
var id ids.ID
if _, err := rand.Read(id[:]); err != nil {
b.Fatal(err)
}
cache.Put(id, n)
}
b.StopTimer()
cache.Flush()
b.StartTimer()
}
}