Skip to content

Commit 55d9506

Browse files
committed
fixup: new benchmark, bigger pool
1 parent e8bfb1f commit 55d9506

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

fieldpath/set_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var randomPathMaker = randomPathAlphabet(MakePathOrDie(
4444
"aac",
4545
"aad",
4646
"aae",
47+
"aaf",
4748
KeyByFields("name", value.StringValue("first")),
4849
KeyByFields("name", value.StringValue("second")),
4950
KeyByFields("port", value.IntValue(443), "protocol", value.StringValue("tcp")),
@@ -63,7 +64,7 @@ func BenchmarkFieldSet(b *testing.B) {
6364
minPathLen int
6465
maxPathLen int
6566
}{
66-
{10, 1, 2},
67+
//{10, 1, 2},
6768
{20, 2, 3},
6869
{50, 2, 4},
6970
{100, 3, 6},
@@ -79,6 +80,11 @@ func BenchmarkFieldSet(b *testing.B) {
7980
}
8081
return x
8182
}
83+
operands := make([]*Set, 500)
84+
for i := range operands {
85+
operands[i] = makeSet()
86+
}
87+
randOperand := func() *Set { return operands[rand.Intn(len(operands))] }
8288

8389
b.Run(fmt.Sprintf("insert-%v", here.size), func(b *testing.B) {
8490
b.ReportAllocs()
@@ -87,35 +93,25 @@ func BenchmarkFieldSet(b *testing.B) {
8793
}
8894
})
8995
b.Run(fmt.Sprintf("has-%v", here.size), func(b *testing.B) {
90-
x := makeSet()
9196
b.ReportAllocs()
92-
b.ResetTimer()
9397
for i := 0; i < b.N; i++ {
94-
x.Has(randomPathMaker.makePath(here.minPathLen, here.maxPathLen))
98+
randOperand().Has(randomPathMaker.makePath(here.minPathLen, here.maxPathLen))
9599
}
96100
})
97101

98-
operands := make([]*Set, 50)
99-
for i := range operands {
100-
operands[i] = makeSet()
101-
}
102-
randOperand := func() *Set { return operands[rand.Intn(len(operands))] }
103102
b.Run(fmt.Sprintf("union-%v", here.size), func(b *testing.B) {
104-
b.ResetTimer()
105103
b.ReportAllocs()
106104
for i := 0; i < b.N; i++ {
107105
randOperand().Union(randOperand())
108106
}
109107
})
110108
b.Run(fmt.Sprintf("intersection-%v", here.size), func(b *testing.B) {
111-
b.ResetTimer()
112109
b.ReportAllocs()
113110
for i := 0; i < b.N; i++ {
114111
randOperand().Intersection(randOperand())
115112
}
116113
})
117114
b.Run(fmt.Sprintf("difference-%v", here.size), func(b *testing.B) {
118-
b.ResetTimer()
119115
b.ReportAllocs()
120116
for i := 0; i < b.N; i++ {
121117
randOperand().Difference(randOperand())

0 commit comments

Comments
 (0)