From 5710165c4bbc4addf0d9eb14e4924dfd0ff5ace1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 21 Jul 2022 18:42:53 +0300 Subject: [PATCH] Add a benchmark for addExtraLabels function --- push_test.go | 2 +- push_timing_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 push_timing_test.go diff --git a/push_test.go b/push_test.go index ec5734e..5eef7ed 100644 --- a/push_test.go +++ b/push_test.go @@ -26,7 +26,7 @@ bar{foo="bar",a="x"} 2 foo 1 # some counter # type foobar counter -foobar{a="b",c="d"} 4`, `x="y"`, `foo{x="y"} 1 + foobar{a="b",c="d"} 4`, `x="y"`, `foo{x="y"} 1 # some counter # type foobar counter foobar{x="y",a="b",c="d"} 4 diff --git a/push_timing_test.go b/push_timing_test.go new file mode 100644 index 0000000..8316143 --- /dev/null +++ b/push_timing_test.go @@ -0,0 +1,20 @@ +package metrics + +import ( + "testing" +) + +func BenchmarkAddExtraLabels(b *testing.B) { + extraLabels := `foo="bar"` + src := []byte(`foo 1 +bar{baz="x"} 2 +`) + b.ReportAllocs() + b.SetBytes(1) + b.RunParallel(func(pb *testing.PB) { + var dst []byte + for pb.Next() { + dst = addExtraLabels(dst[:0], src, extraLabels) + } + }) +}