mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Do test fixture setup outside cel.UnstructuredToVal benchmark loop.
This commit is contained in:
parent
0fe0dbf3fb
commit
91179d4ce4
@ -621,44 +621,48 @@ func TestMapper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUnstructuredToVal(b *testing.B) {
|
func BenchmarkUnstructuredToVal(b *testing.B) {
|
||||||
|
u := []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "a",
|
||||||
|
"val": 1,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "b",
|
||||||
|
"val": 2,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "@b",
|
||||||
|
"val": 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
if val := UnstructuredToVal([]interface{}{
|
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
|
||||||
map[string]interface{}{
|
|
||||||
"key": "a",
|
|
||||||
"val": 1,
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"key": "b",
|
|
||||||
"val": 2,
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"key": "@b",
|
|
||||||
"val": 2,
|
|
||||||
},
|
|
||||||
}, &mapListSchema); val == nil {
|
|
||||||
b.Fatal(val)
|
b.Fatal(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUnstructuredToValWithEscape(b *testing.B) {
|
func BenchmarkUnstructuredToValWithEscape(b *testing.B) {
|
||||||
|
u := []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "a.1",
|
||||||
|
"val": "__i.1",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "b.1",
|
||||||
|
"val": 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
if val := UnstructuredToVal([]interface{}{
|
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
|
||||||
map[string]interface{}{
|
|
||||||
"key": "a.1",
|
|
||||||
"val": "__i.1",
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"key": "b.1",
|
|
||||||
"val": 2,
|
|
||||||
},
|
|
||||||
}, &mapListSchema); val == nil {
|
|
||||||
b.Fatal(val)
|
b.Fatal(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user