We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 42e8297 commit abcdb7dCopy full SHA for abcdb7d
bench_test.go
@@ -38,20 +38,23 @@ func nrand(n int) []int {
38
return i
39
}
40
41
-func benchAdd(b *testing.B, s Set[int]) {
42
- nums := nrand(b.N)
+func benchAdd(b *testing.B, n int, newSet func(...int) Set[int]) {
+ nums := nrand(n)
43
b.ResetTimer()
44
- for _, v := range nums {
45
- s.Add(v)
+ for i := 0; i < b.N; i++ {
+ s := newSet()
46
+ for _, v := range nums {
47
+ s.Add(v)
48
+ }
49
50
51
52
func BenchmarkAddSafe(b *testing.B) {
- benchAdd(b, NewSet[int]())
53
+ benchAdd(b, 1000, NewSet[int])
54
55
56
func BenchmarkAddUnsafe(b *testing.B) {
- benchAdd(b, NewThreadUnsafeSet[int]())
57
+ benchAdd(b, 1000, NewThreadUnsafeSet[int])
58
59
60
func benchRemove(b *testing.B, s Set[int]) {
0 commit comments