Skip to content

Commit 45a778a

Browse files
author
Antoine Pelisse
committed
Benchmark both Update and Apply
1 parent 9db5fb9 commit 45a778a

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

merge/real_test.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ limitations under the License.
1717
package merge_test
1818

1919
import (
20+
"fmt"
2021
"io/ioutil"
2122
"path/filepath"
23+
"strings"
2224
"testing"
2325

2426
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
@@ -37,6 +39,10 @@ func read(file string) []byte {
3739
return s
3840
}
3941

42+
func lastPart(s string) string {
43+
return s[strings.LastIndex(s, ".")+1:]
44+
}
45+
4046
var parser = func() *typed.Parser {
4147
s := read(testdata("k8s-schema.yaml"))
4248
parser, err := typed.NewParser(typed.YAMLObject(s))
@@ -46,7 +52,7 @@ var parser = func() *typed.Parser {
4652
return parser
4753
}()
4854

49-
func BenchmarkUpdates(b *testing.B) {
55+
func BenchmarkOperations(b *testing.B) {
5056
benches := []struct {
5157
typename string
5258
obj typed.YAMLObject
@@ -66,26 +72,37 @@ func BenchmarkUpdates(b *testing.B) {
6672
}
6773

6874
for _, bench := range benches {
69-
b.Run(bench.typename, func(b *testing.B) {
70-
test := TestCase{
71-
Ops: []Operation{
72-
Update{
73-
Manager: "controller",
74-
APIVersion: "v1",
75-
Object: bench.obj,
76-
},
75+
76+
b.Run(lastPart(bench.typename), func(b *testing.B) {
77+
ops := []Operation{
78+
Update{
79+
Manager: "controller",
80+
APIVersion: "v1",
81+
Object: bench.obj,
82+
},
83+
Apply{
84+
Manager: "controller",
85+
APIVersion: "v1",
86+
Object: bench.obj,
7787
},
7888
}
89+
for _, op := range ops {
90+
b.Run(lastPart(fmt.Sprintf("%T", op)), func(b *testing.B) {
91+
test := TestCase{
92+
Ops: []Operation{op},
93+
}
7994

80-
pt := parser.Type(bench.typename)
81-
test.PreprocessOperations(pt)
95+
pt := parser.Type(bench.typename)
96+
test.PreprocessOperations(pt)
8297

83-
b.ReportAllocs()
84-
b.ResetTimer()
85-
for n := 0; n < b.N; n++ {
86-
if err := test.Bench(pt); err != nil {
87-
b.Fatal(err)
88-
}
98+
b.ReportAllocs()
99+
b.ResetTimer()
100+
for n := 0; n < b.N; n++ {
101+
if err := test.Bench(pt); err != nil {
102+
b.Fatal(err)
103+
}
104+
}
105+
})
89106
}
90107
})
91108
}

0 commit comments

Comments
 (0)