From a07a0be024ade806b7a8fbcf58a241a307f1ab8b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 6 Mar 2023 18:17:31 +0000 Subject: [PATCH] Add benchmark for labels.Builder Signed-off-by: Bryan Boreham --- model/labels/labels_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/model/labels/labels_test.go b/model/labels/labels_test.go index 1902f2f71..4832be337 100644 --- a/model/labels/labels_test.go +++ b/model/labels/labels_test.go @@ -696,6 +696,31 @@ func BenchmarkLabels_Hash(b *testing.B) { } } +func BenchmarkBuilder(b *testing.B) { + m := []Label{ + {"job", "node"}, + {"instance", "123.123.1.211:9090"}, + {"path", "/api/v1/namespaces//deployments/"}, + {"method", "GET"}, + {"namespace", "system"}, + {"status", "500"}, + {"prometheus", "prometheus-core-1"}, + {"datacenter", "eu-west-1"}, + {"pod_name", "abcdef-99999-defee"}, + } + + var l Labels + builder := NewBuilder(EmptyLabels()) + for i := 0; i < b.N; i++ { + builder.Reset(EmptyLabels()) + for _, l := range m { + builder.Set(l.Name, l.Value) + } + l = builder.Labels(EmptyLabels()) + } + require.Equal(b, 9, l.Len()) +} + func BenchmarkLabels_Copy(b *testing.B) { m := map[string]string{ "job": "node",