@@ -17,8 +17,10 @@ limitations under the License.
17
17
package merge_test
18
18
19
19
import (
20
+ "fmt"
20
21
"io/ioutil"
21
22
"path/filepath"
23
+ "strings"
22
24
"testing"
23
25
24
26
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
@@ -37,6 +39,10 @@ func read(file string) []byte {
37
39
return s
38
40
}
39
41
42
+ func lastPart (s string ) string {
43
+ return s [strings .LastIndex (s , "." )+ 1 :]
44
+ }
45
+
40
46
var parser = func () * typed.Parser {
41
47
s := read (testdata ("k8s-schema.yaml" ))
42
48
parser , err := typed .NewParser (typed .YAMLObject (s ))
@@ -46,7 +52,7 @@ var parser = func() *typed.Parser {
46
52
return parser
47
53
}()
48
54
49
- func BenchmarkUpdates (b * testing.B ) {
55
+ func BenchmarkOperations (b * testing.B ) {
50
56
benches := []struct {
51
57
typename string
52
58
obj typed.YAMLObject
@@ -66,26 +72,37 @@ func BenchmarkUpdates(b *testing.B) {
66
72
}
67
73
68
74
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 ,
77
87
},
78
88
}
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
+ }
79
94
80
- pt := parser .Type (bench .typename )
81
- test .PreprocessOperations (pt )
95
+ pt := parser .Type (bench .typename )
96
+ test .PreprocessOperations (pt )
82
97
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
+ })
89
106
}
90
107
})
91
108
}
0 commit comments