Merge pull request #110548 from benluddy/cel-unstructuredtoval-benchmark-fixture

Do test fixture setup outside cel.UnstructuredToVal benchmark loop.
This commit is contained in:
Kubernetes Prow Robot 2022-06-29 03:36:05 -07:00 committed by GitHub
commit d0f5496d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -621,11 +621,7 @@ func TestMapper(t *testing.T) {
} }
func BenchmarkUnstructuredToVal(b *testing.B) { func BenchmarkUnstructuredToVal(b *testing.B) {
b.ReportAllocs() u := []interface{}{
b.ResetTimer()
for n := 0; n < b.N; n++ {
if val := UnstructuredToVal([]interface{}{
map[string]interface{}{ map[string]interface{}{
"key": "a", "key": "a",
"val": 1, "val": 1,
@ -638,18 +634,20 @@ func BenchmarkUnstructuredToVal(b *testing.B) {
"key": "@b", "key": "@b",
"val": 2, "val": 2,
}, },
}, &mapListSchema); val == nil { }
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
b.Fatal(val) b.Fatal(val)
} }
} }
} }
func BenchmarkUnstructuredToValWithEscape(b *testing.B) { func BenchmarkUnstructuredToValWithEscape(b *testing.B) {
b.ReportAllocs() u := []interface{}{
b.ResetTimer()
for n := 0; n < b.N; n++ {
if val := UnstructuredToVal([]interface{}{
map[string]interface{}{ map[string]interface{}{
"key": "a.1", "key": "a.1",
"val": "__i.1", "val": "__i.1",
@ -658,7 +656,13 @@ func BenchmarkUnstructuredToValWithEscape(b *testing.B) {
"key": "b.1", "key": "b.1",
"val": 2, "val": 2,
}, },
}, &mapListSchema); val == nil { }
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
b.Fatal(val) b.Fatal(val)
} }
} }