-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_bench_test.go
73 lines (59 loc) · 1.27 KB
/
get_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
64
65
66
67
68
69
70
71
72
73
package sortedmap
import "testing"
func get1ofNRecords(b *testing.B, n int) {
sm, _, keys, err := newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Get(keys[0])
b.StopTimer()
sm, _, keys, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func batchGetNofNRecords(b *testing.B, n int) {
sm, _, keys, err := newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.BatchGet(keys)
b.StopTimer()
sm, _, keys, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func BenchmarkGet1of1CachedRecords(b *testing.B) {
sm, _, keys, err := newRandSortedMapWithKeys(1)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Get(keys[0])
}
}
func BenchmarkGet1of1Records(b *testing.B) {
get1ofNRecords(b, 1)
}
func BenchmarkBatchGet10of10Records(b *testing.B) {
batchGetNofNRecords(b, 10)
}
func BenchmarkBatchGet100of100Records(b *testing.B) {
batchGetNofNRecords(b, 100)
}
func BenchmarkBatchGet1000of1000Records(b *testing.B) {
batchGetNofNRecords(b, 1000)
}
func BenchmarkBatchGet10000of10000Records(b *testing.B) {
batchGetNofNRecords(b, 10000)
}