Skip to content

Commit 1ad9a28

Browse files
authored
Merge pull request #125 from apelisse/perf/benchmark-updates
Add additional benchmarks for "updates"
2 parents ea1e6ca + 9233339 commit 1ad9a28

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

merge/real_test.go

+59-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package merge_test
1818

1919
import (
20-
"fmt"
2120
"io/ioutil"
2221
"path/filepath"
2322
"strings"
@@ -76,33 +75,74 @@ func BenchmarkOperations(b *testing.B) {
7675
}
7776

7877
for _, bench := range benches {
79-
8078
b.Run(lastPart(bench.typename), func(b *testing.B) {
81-
ops := []Operation{
82-
Update{
83-
Manager: "controller",
84-
APIVersion: "v1",
85-
Object: bench.obj,
79+
tests := []struct {
80+
name string
81+
ops []Operation
82+
}{
83+
{
84+
name: "Create",
85+
ops: []Operation{
86+
Update{
87+
Manager: "controller",
88+
APIVersion: "v1",
89+
Object: bench.obj,
90+
},
91+
},
92+
},
93+
{
94+
name: "Apply",
95+
ops: []Operation{
96+
Apply{
97+
Manager: "controller",
98+
APIVersion: "v1",
99+
Object: bench.obj,
100+
},
101+
},
102+
},
103+
{
104+
name: "Update",
105+
ops: []Operation{
106+
Update{
107+
Manager: "controller",
108+
APIVersion: "v1",
109+
Object: bench.obj,
110+
},
111+
Update{
112+
Manager: "other-controller",
113+
APIVersion: "v1",
114+
Object: bench.obj,
115+
},
116+
},
86117
},
87-
Apply{
88-
Manager: "controller",
89-
APIVersion: "v1",
90-
Object: bench.obj,
118+
{
119+
name: "UpdateVersion",
120+
ops: []Operation{
121+
Update{
122+
Manager: "controller",
123+
APIVersion: "v1",
124+
Object: bench.obj,
125+
},
126+
Update{
127+
Manager: "other-controller",
128+
APIVersion: "v2",
129+
Object: bench.obj,
130+
},
131+
},
91132
},
92133
}
93-
for _, op := range ops {
94-
b.Run(lastPart(fmt.Sprintf("%T", op)), func(b *testing.B) {
95-
test := TestCase{
96-
Ops: []Operation{op},
97-
}
98-
134+
for _, test := range tests {
135+
b.Run(test.name, func(b *testing.B) {
99136
pt := parser.Type(bench.typename)
100-
test.PreprocessOperations(pt)
137+
tc := TestCase{
138+
Ops: test.ops,
139+
}
140+
tc.PreprocessOperations(pt)
101141

102142
b.ReportAllocs()
103143
b.ResetTimer()
104144
for n := 0; n < b.N; n++ {
105-
if err := test.Bench(pt); err != nil {
145+
if err := tc.Bench(pt); err != nil {
106146
b.Fatal(err)
107147
}
108148
}

0 commit comments

Comments
 (0)