From 91179d4ce421adf09de08f7084771b57b483cae2 Mon Sep 17 00:00:00 2001 From: Ben Luddy Date: Mon, 13 Jun 2022 15:23:25 -0400 Subject: [PATCH] Do test fixture setup outside cel.UnstructuredToVal benchmark loop. --- .../pkg/apiserver/schema/cel/values_test.go | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/values_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/values_test.go index a6656256965..2ad65a07538 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/values_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/values_test.go @@ -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) } }