Skip to content

Commit

Permalink
Merge pull request #110548 from benluddy/cel-unstructuredtoval-benchm…
Browse files Browse the repository at this point in the history
…ark-fixture

Do test fixture setup outside cel.UnstructuredToVal benchmark loop.
  • Loading branch information
k8s-ci-robot committed Jun 29, 2022
2 parents ab4aa18 + 91179d4 commit d0f5496
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,44 +621,48 @@ func TestMapper(t *testing.T) {
}

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.ResetTimer()

for n := 0; n < b.N; n++ {
if val := UnstructuredToVal([]interface{}{
map[string]interface{}{
"key": "a",
"val": 1,
},
map[string]interface{}{
"key": "b",
"val": 2,
},
map[string]interface{}{
"key": "@b",
"val": 2,
},
}, &mapListSchema); val == nil {
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
b.Fatal(val)
}
}
}

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.ResetTimer()

for n := 0; n < b.N; n++ {
if val := UnstructuredToVal([]interface{}{
map[string]interface{}{
"key": "a.1",
"val": "__i.1",
},
map[string]interface{}{
"key": "b.1",
"val": 2,
},
}, &mapListSchema); val == nil {
if val := UnstructuredToVal(u, &mapListSchema); val == nil {
b.Fatal(val)
}
}
Expand Down

0 comments on commit d0f5496

Please sign in to comment.