diff options
| -rw-r--r-- | microprom/labels_test.go | 25 |
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) + } + }) +} |
