-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlinkedhashset_benchmark_test.go
More file actions
55 lines (50 loc) · 1.17 KB
/
linkedhashset_benchmark_test.go
File metadata and controls
55 lines (50 loc) · 1.17 KB
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
package set
import (
"fmt"
"testing"
)
func BenchmarkLinkedHashSet_Contains_vs_InArray(b *testing.B) {
total := len(giantGenericSlice)
step := total / 5
sizes := []int{step, 2 * step, 3 * step, 4 * step, total}
for _, n := range sizes {
b.Run(fmt.Sprintf("N=%d", n), func(b *testing.B) {
set := NewLinkedHashSet[string]()
set.Add(giantGenericSlice[:n]...)
foundTarget := giantGenericSlice[n/2]
notFoundTarget := "___not_present___"
b.Run("Found/Contains", func(b *testing.B) {
b.ReportAllocs()
var sink bool
for i := 0; i < b.N; i++ {
sink = set.Contains(foundTarget)
}
_ = sink
})
b.Run("Found/InArray", func(b *testing.B) {
b.ReportAllocs()
var sink bool
for i := 0; i < b.N; i++ {
sink = set.InArray(foundTarget)
}
_ = sink
})
b.Run("NotFound/Contains", func(b *testing.B) {
b.ReportAllocs()
var sink bool
for i := 0; i < b.N; i++ {
sink = set.Contains(notFoundTarget)
}
_ = sink
})
b.Run("NotFound/InArray", func(b *testing.B) {
b.ReportAllocs()
var sink bool
for i := 0; i < b.N; i++ {
sink = set.InArray(notFoundTarget)
}
_ = sink
})
})
}
}