-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
154 lines (135 loc) · 2.32 KB
/
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package iterset
import (
"iter"
"maps"
"math/rand"
"slices"
"testing"
)
const size = 100_000
func setup(b *testing.B) (MapSet[int, struct{}], iter.Seq[int]) {
defer b.ResetTimer()
s := Set[int]()
for range size / 4 {
s.Add(rand.Intn(size))
}
k := make([]int, size/2)
for i := range k {
k[i] = rand.Intn(size)
}
return s, slices.Values(k)
}
func BenchmarkMapSet_Equal(b *testing.B) {
s, k := setup(b)
for range b.N {
s.Equal(k)
}
}
func BenchmarkEqual(b *testing.B) {
s, k := setup(b)
for range b.N {
Equal(maps.Keys(s), k)
}
}
func BenchmarkEqualCounts(b *testing.B) {
s, k := setup(b)
for range b.N {
EqualCounts(maps.Keys(s), k)
}
}
func BenchmarkMapSet_IsSubset(b *testing.B) {
s, k := setup(b)
for range b.N {
s.IsSubset(k)
}
}
func BenchmarkIsSubset(b *testing.B) {
s, k := setup(b)
for range b.N {
IsSubset(maps.Keys(s), k)
}
}
func BenchmarkMapSet_IsSuperset(b *testing.B) {
s, k := setup(b)
for range b.N {
s.IsSuperset(k)
}
}
func BenchmarkMapSet_IsDisjoint(b *testing.B) {
s, k := setup(b)
for range b.N {
s.IsDisjoint(k)
}
}
func BenchmarkIsDisjoint(b *testing.B) {
s, k := setup(b)
for range b.N {
IsDisjoint(maps.Keys(s), k)
}
}
func BenchmarkMapSet_Intersect(b *testing.B) {
s, k := setup(b)
for range b.N {
for range s.Intersect(k) {
}
}
}
func BenchmarkIntersect(b *testing.B) {
s, k := setup(b)
for range b.N {
for range Intersect(maps.Keys(s), k) {
}
}
}
func BenchmarkMapSet_Difference(b *testing.B) {
s, k := setup(b)
for range b.N {
for range s.Difference(k) {
}
}
}
func BenchmarkDifference(b *testing.B) {
s, k := setup(b)
for range b.N {
for range Difference(maps.Keys(s), k) {
}
}
}
func BenchmarkMapSet_ReverseDifference(b *testing.B) {
s, k := setup(b)
for range b.N {
for range s.ReverseDifference(k) {
}
}
}
func BenchmarkMapSet_SymmetricDifference(b *testing.B) {
s, k := setup(b)
for range b.N {
for range s.SymmetricDifference(k) {
}
}
}
func BenchmarkUnique(b *testing.B) {
_, k := setup(b)
for range b.N {
for range Unique(k) {
}
}
}
func BenchmarkCompact(b *testing.B) {
_, k := setup(b)
s := slices.Values(slices.Sorted(k))
b.ResetTimer()
for range b.N {
for range Compact(s) {
}
}
}
func BenchmarkSet(b *testing.B) {
_, k := setup(b)
s := slices.Collect(k)
b.ResetTimer()
for range b.N {
Set(s...)
}
}