-
Notifications
You must be signed in to change notification settings - Fork 8
/
has_bench_test.go
73 lines (59 loc) · 1.27 KB
/
has_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 has1ofNRecords(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.Has(keys[0])
b.StopTimer()
sm, _, keys, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func batchHasNofNRecords(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.BatchHas(keys)
b.StopTimer()
sm, _, keys, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func BenchmarkHas1of1CachedRecords(b *testing.B) {
sm, _, keys, err := newRandSortedMapWithKeys(1)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Has(keys[0])
}
}
func BenchmarkHas1of1Records(b *testing.B) {
has1ofNRecords(b, 1)
}
func BenchmarkBatchHas10of10Records(b *testing.B) {
batchHasNofNRecords(b, 10)
}
func BenchmarkBatchHas100of100Records(b *testing.B) {
batchHasNofNRecords(b, 100)
}
func BenchmarkBatchHas1000of1000Records(b *testing.B) {
batchHasNofNRecords(b, 1000)
}
func BenchmarkBatchHas10000of10000Records(b *testing.B) {
batchHasNofNRecords(b, 10000)
}