From 19c23949154b11c67f8ae9fc6f9863b2a8dbba46 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Thu, 20 May 2021 17:00:07 +0000 Subject: [PATCH] Add benchmark for LabelSelectorAsSelector --- .../pkg/apis/meta/v1/helpers_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go index 85bb868a85b..ff22f6babcf 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go @@ -93,6 +93,26 @@ func TestLabelSelectorAsSelector(t *testing.T) { } } +func BenchmarkLabelSelectorAsSelector(b *testing.B) { + selector := &LabelSelector{ + MatchLabels: map[string]string{ + "foo": "foo", + "bar": "bar", + }, + MatchExpressions: []LabelSelectorRequirement{{ + Key: "baz", + Operator: LabelSelectorOpExists, + }}, + } + b.StartTimer() + for i := 0; i < b.N; i++ { + _, err := LabelSelectorAsSelector(selector) + if err != nil { + b.Fatal(err) + } + } +} + func TestLabelSelectorAsMap(t *testing.T) { matchLabels := map[string]string{"foo": "bar"} matchExpressions := func(operator LabelSelectorOperator, values []string) []LabelSelectorRequirement {