@@ -42,7 +42,7 @@ func lastPart(s string) string {
42
42
return s [strings .LastIndex (s , "." )+ 1 :]
43
43
}
44
44
45
- func BenchmarkFromUnstructured (b * testing.B ) {
45
+ func BenchmarkConvertUnstructured (b * testing.B ) {
46
46
tests := []struct {
47
47
typename string
48
48
obj []byte
@@ -75,22 +75,33 @@ func BenchmarkFromUnstructured(b *testing.B) {
75
75
}
76
76
77
77
for _ , test := range tests {
78
- b .Run (lastPart (test .typename ), func (b * testing.B ) {
79
- pt := parser .Type (test .typename )
78
+ pt := parser .Type (test .typename )
80
79
81
- obj := map [string ]interface {}{}
82
- if err := yaml .Unmarshal (test .obj , & obj ); err != nil {
83
- b .Fatal (err )
84
- }
80
+ obj := map [string ]interface {}{}
81
+ if err := yaml .Unmarshal (test .obj , & obj ); err != nil {
82
+ b .Fatal (err )
83
+ }
85
84
86
- b .ReportAllocs ()
87
- b .ResetTimer ()
88
- for n := 0 ; n < b .N ; n ++ {
89
- if _ , err := pt .FromUnstructured (obj ); err != nil {
90
- b .Fatal (err )
85
+ b .Run (lastPart (test .typename ), func (b * testing.B ) {
86
+ var u * typed.TypedValue
87
+ b .Run ("From" , func (b * testing.B ) {
88
+ b .ReportAllocs ()
89
+ b .ResetTimer ()
90
+ for n := 0 ; n < b .N ; n ++ {
91
+ var err error
92
+ if u , err = pt .FromUnstructured (obj ); err != nil {
93
+ b .Fatal (err )
94
+ }
91
95
}
92
- }
96
+ })
97
+ b .Run ("To" , func (b * testing.B ) {
98
+ b .ReportAllocs ()
99
+ b .ResetTimer ()
100
+
101
+ for n := 0 ; n < b .N ; n ++ {
102
+ _ = u .AsValue ().ToUnstructured (false )
103
+ }
104
+ })
93
105
})
94
106
}
95
-
96
107
}
0 commit comments