From 732be39b4b1ce4f2154ff9a9bfb93eee3c27b263 Mon Sep 17 00:00:00 2001 From: Clayton O'Neill Date: Thu, 16 May 2019 17:15:38 -0400 Subject: [PATCH] Add benchmark for hashNameAndLabels Signed-off-by: Clayton O'Neill --- exporter_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/exporter_test.go b/exporter_test.go index 7e85120..0ad3002 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -822,3 +822,46 @@ func BenchmarkParseDogStatsDTagsToLabels(b *testing.B) { }) } } + +func BenchmarkHashNameAndLabels(b *testing.B) { + scenarios := []struct { + name string + metric string + labels map[string]string + }{ + { + name: "no labels", + metric: "counter", + labels: map[string]string{}, + }, { + name: "one label", + metric: "counter", + labels: map[string]string{ + "label": "value", + }, + }, { + name: "many labels", + metric: "counter", + labels: map[string]string{ + "label0": "value", + "label1": "value", + "label2": "value", + "label3": "value", + "label4": "value", + "label5": "value", + "label6": "value", + "label7": "value", + "label8": "value", + "label9": "value", + }, + }, + } + + for _, s := range scenarios { + b.Run(s.name, func(b *testing.B) { + for n := 0; n < b.N; n++ { + hashNameAndLabels(s.metric, s.labels) + } + }) + } +}