Skip to content

Commit

Permalink
test: fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
orisano authored and deckarep committed Mar 29, 2022
1 parent 42e8297 commit abcdb7d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ func nrand(n int) []int {
return i
}

func benchAdd(b *testing.B, s Set[int]) {
nums := nrand(b.N)
func benchAdd(b *testing.B, n int, newSet func(...int) Set[int]) {
nums := nrand(n)
b.ResetTimer()
for _, v := range nums {
s.Add(v)
for i := 0; i < b.N; i++ {
s := newSet()
for _, v := range nums {
s.Add(v)
}
}
}

func BenchmarkAddSafe(b *testing.B) {
benchAdd(b, NewSet[int]())
benchAdd(b, 1000, NewSet[int])
}

func BenchmarkAddUnsafe(b *testing.B) {
benchAdd(b, NewThreadUnsafeSet[int]())
benchAdd(b, 1000, NewThreadUnsafeSet[int])
}

func benchRemove(b *testing.B, s Set[int]) {
Expand Down

0 comments on commit abcdb7d

Please sign in to comment.