-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
90 lines (65 loc) · 1.41 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package fibheap
import "testing"
func benchmarkPush(b *testing.B, items []*mockItem) {
b.Helper()
for i := 0; i < b.N; i++ {
h := NewHeap()
for _, item := range items {
h.Push(item)
}
}
}
func BenchmarkHeap_Push1000(b *testing.B) {
items := generateMockItems(1000)
b.ResetTimer()
benchmarkPush(b, items)
}
func BenchmarkHeap_Push10000(b *testing.B) {
items := generateMockItems(10000)
b.ResetTimer()
benchmarkPush(b, items)
}
func BenchmarkHeap_Push100000(b *testing.B) {
items := generateMockItems(100000)
b.ResetTimer()
benchmarkPush(b, items)
}
func BenchmarkHeap_Push1000000(b *testing.B) {
items := generateMockItems(1000000)
b.ResetTimer()
benchmarkPush(b, items)
}
func benchmarkPop(b *testing.B, items []*mockItem) {
b.Helper()
for i := 0; i < b.N; i++ {
h := NewHeap()
b.StopTimer()
for _, item := range items {
h.Push(item)
}
b.StartTimer()
for h.Size() > 0 {
h.Pop()
}
}
}
func BenchmarkHeap_Pop1000(b *testing.B) {
items := generateMockItems(1000)
b.ResetTimer()
benchmarkPop(b, items)
}
func BenchmarkHeap_Pop10000(b *testing.B) {
items := generateMockItems(10000)
b.ResetTimer()
benchmarkPop(b, items)
}
func BenchmarkHeap_Pop100000(b *testing.B) {
items := generateMockItems(100000)
b.ResetTimer()
benchmarkPop(b, items)
}
func BenchmarkHeap_Pop1000000(b *testing.B) {
items := generateMockItems(1000000)
b.ResetTimer()
benchmarkPop(b, items)
}