-
Notifications
You must be signed in to change notification settings - Fork 8
/
replace_bench_test.go
77 lines (61 loc) · 1.49 KB
/
replace_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
74
75
76
77
package sortedmap
import "testing"
func replace1ofNRecords(b *testing.B, n int) {
sm, records, _, err := newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Replace(records[0].Key, records[0].Val)
b.StopTimer()
sm, records, _, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func batchReplaceNofNRecords(b *testing.B, n int) {
sm, records, _, err := newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.BatchReplace(records)
b.StopTimer()
sm, records, _, err = newRandSortedMapWithKeys(n)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
func BenchmarkReplace1of1Records(b *testing.B) {
replace1ofNRecords(b, 1)
}
func BenchmarkReplace1of10Records(b *testing.B) {
replace1ofNRecords(b, 10)
}
func BenchmarkReplace1of100Records(b *testing.B) {
replace1ofNRecords(b, 100)
}
func BenchmarkReplace1of1000Records(b *testing.B) {
replace1ofNRecords(b, 1000)
}
func BenchmarkReplace1of10000Records(b *testing.B) {
replace1ofNRecords(b, 10000)
}
func BenchmarkBatchReplace10of10Records(b *testing.B) {
batchReplaceNofNRecords(b, 10)
}
func BenchmarkBatchReplace100of100Records(b *testing.B) {
batchReplaceNofNRecords(b, 100)
}
func BenchmarkBatchReplace1000of1000Records(b *testing.B) {
batchReplaceNofNRecords(b, 1000)
}
func BenchmarkBatchReplace10000of10000Records(b *testing.B) {
batchReplaceNofNRecords(b, 10000)
}