-
Notifications
You must be signed in to change notification settings - Fork 8
/
insert_bench_test.go
57 lines (44 loc) · 1003 Bytes
/
insert_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
package sortedmap
import (
"testing"
"github.com/umpc/go-sortedmap/asc"
)
func insertRecord(b *testing.B) {
records := randRecords(1)
sm := New(0, asc.Time)
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Insert(records[0].Key, records[0].Val)
b.StopTimer()
records = randRecords(1)
sm = New(0, asc.Time)
b.StartTimer()
}
}
func batchInsertRecords(b *testing.B, n int) {
records := randRecords(n)
sm := New(0, asc.Time)
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.BatchInsert(records)
b.StopTimer()
records = randRecords(n)
sm = New(0, asc.Time)
b.StartTimer()
}
}
func BenchmarkInsert1Record(b *testing.B) {
insertRecord(b)
}
func BenchmarkBatchInsert10Records(b *testing.B) {
batchInsertRecords(b, 10)
}
func BenchmarkBatchInsert100Records(b *testing.B) {
batchInsertRecords(b, 100)
}
func BenchmarkBatchInsert1000Records(b *testing.B) {
batchInsertRecords(b, 1000)
}
func BenchmarkBatchInsert10000Records(b *testing.B) {
batchInsertRecords(b, 10000)
}