concurrency benchmark

This commit is contained in:
Robert Vollmert 2015-11-09 14:34:37 +01:00
parent 449ccefff1
commit 39a26f2e35
1 changed files with 24 additions and 0 deletions

View File

@ -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{