aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-08-18 13:46:02 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-08-18 13:46:02 +0200
commit75c6aa5a5d3b5c65cc63ab34c90fa24cecc75f65 (patch)
tree5508a49d5d2a03f4a970a1f32a5c559b90217d9c
parent5cc0f9db288ffaf44d104974707338d52530cece (diff)
downloadgo-gg-75c6aa5a5d3b5c65cc63ab34c90fa24cecc75f65.tar.gz
microprom: add BenchmarkFormatLabels
-rw-r--r--microprom/labels_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/microprom/labels_test.go b/microprom/labels_test.go
index 0414be8..291d1da 100644
--- a/microprom/labels_test.go
+++ b/microprom/labels_test.go
@@ -4,6 +4,7 @@
package microprom_test
import (
+ "fmt"
"testing"
"go.xyrillian.de/gg/assert"
@@ -22,3 +23,27 @@ func TestFormatLabels(t *testing.T) {
labels = ms.FormatLabels(names, "bar\\\n\\bar", `"universe\world"`)
assert.Equal(t, labels, `foo="bar\\\n\\bar",hello="\"universe\\world\""`)
}
+
+func BenchmarkFormatLabels(b *testing.B) {
+ ms := microprom.NewMetricSet(microprom.SyntaxPrometheusLegacy, nil)
+ const (
+ appVersion = "1.2.3"
+ node = "fcae8f43-87d4-4644-b28c-7bb1c340fcea"
+ region = "us-east"
+ status = "404"
+ )
+ names := microprom.NewLabelNames("app_version", "node", "region", "status")
+
+ b.Run("method=fmt.Sprintf", func(b *testing.B) {
+ for b.Loop() {
+ _ = fmt.Sprintf(`app_version=%q,node=%q,region=%q,status=%q`,
+ appVersion, node, region, status,
+ )
+ }
+ })
+ b.Run("method=FormatLabels", func(b *testing.B) {
+ for b.Loop() {
+ _ = ms.FormatLabels(names, appVersion, node, region, status)
+ }
+ })
+}