From 7f70979120e9580078b3bb44cd97c8d4df3d7a78 Mon Sep 17 00:00:00 2001 From: Brian Akins Date: Tue, 9 Apr 2019 11:56:58 -0400 Subject: [PATCH] Add Benchmarks for escapeMetricName Signed-off-by: Brian Akins --- exporter_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/exporter_test.go b/exporter_test.go index fc0d0b1..e3ba4ce 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -413,3 +413,24 @@ func getTelemetryCounterValue(counter prometheus.Counter) float64 { } return metric.Counter.GetValue() } + +func BenchmarkEscapeMetricName(b *testing.B) { + scenarios := []string{ + "clean", + "0starts_with_digit", + "with_underscore", + "with.dot", + "with😱emoji", + "with.*.multiple", + "test.web-server.foo.bar", + "", + } + + for _, s := range scenarios { + b.Run(s, func(b *testing.B) { + for n := 0; n < b.N; n++ { + escapeMetricName(s) + } + }) + } +}