From 1b0c9905b24c29e4f716f0f74d9f253faff0c502 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 5 Jun 2024 10:07:42 +0100 Subject: [PATCH] Labels: add BenchmarkScratchBuilder_Equal Signed-off-by: Bryan Boreham --- model/labels/labels_dedupelabels_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/model/labels/labels_dedupelabels_test.go b/model/labels/labels_dedupelabels_test.go index 5ef9255c21..9064cadc60 100644 --- a/model/labels/labels_dedupelabels_test.go +++ b/model/labels/labels_dedupelabels_test.go @@ -48,3 +48,18 @@ func TestVarint(t *testing.T) { } require.Panics(t, func() { encodeVarint(buf[:], len(buf), 1<<29) }) } + +func BenchmarkScratchBuilder_Equal(b *testing.B) { + for _, scenario := range comparisonBenchmarkScenarios { + builder := NewScratchBuilder(scenario.base.Len()) + scenario.base.Range(func(l Label) { + builder.Add(l.Name, l.Value) + }) + b.Run(scenario.desc, func(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = builder.Equal(scenario.other) + } + }) + } +}