From 39a26f2e350fe8474b6137fa63d717db1c2161d8 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Mon, 9 Nov 2015 14:34:37 +0100 Subject: [PATCH] concurrency benchmark --- prometheus/benchmark_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/prometheus/benchmark_test.go b/prometheus/benchmark_test.go index 6ae7333..a3d8669 100644 --- a/prometheus/benchmark_test.go +++ b/prometheus/benchmark_test.go @@ -14,6 +14,7 @@ package prometheus import ( + "sync" "testing" ) @@ -32,6 +33,29 @@ func BenchmarkCounterWithLabelValues(b *testing.B) { } } +func BenchmarkCounterWithLabelValuesConcurrent(b *testing.B) { + m := NewCounterVec( + CounterOpts{ + Name: "benchmark_counter", + Help: "A counter to benchmark it.", + }, + []string{"one", "two", "three"}, + ) + b.ReportAllocs() + b.ResetTimer() + wg := sync.WaitGroup{} + for i := 0; i < 10; i++ { + wg.Add(1) + go func() { + for j := 0; j < b.N/10; j++ { + m.WithLabelValues("eins", "zwei", "drei").Inc() + } + wg.Done() + }() + } + wg.Wait() +} + func BenchmarkCounterWithMappedLabels(b *testing.B) { m := NewCounterVec( CounterOpts{