-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics_bench_test.go
46 lines (37 loc) · 1.06 KB
/
metrics_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gotoprom_test
import (
"testing"
"github.com/cabify/gotoprom"
"github.com/cabify/gotoprom/prometheusvanilla"
"github.com/prometheus/client_golang/prometheus"
)
func BenchmarkVanilla(b *testing.B) {
prometheus.DefaultRegisterer = prometheus.NewRegistry()
cvec := prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "benchmarks",
Name: "do_add1",
Help: "does an add",
}, []string{"region"})
prometheus.MustRegister(cvec)
b.ResetTimer()
for n := 0; n < b.N; n++ {
cvec.With(map[string]string{
"region": "madrid",
}).Add(1)
}
}
func BenchmarkGotoprom(b *testing.B) {
type labels struct {
Region string `label:"region"`
}
var metrics struct {
DoAdd func(labels) prometheus.Counter `name:"do_add2" help:"does an add"`
}
initializer := gotoprom.NewInitializer(prometheus.NewRegistry())
initializer.MustAddBuilder(prometheusvanilla.CounterType, prometheusvanilla.BuildCounter)
initializer.MustInit(&metrics, "benchmarks")
b.ResetTimer()
for n := 0; n < b.N; n++ {
metrics.DoAdd(labels{Region: "madrid"}).Add(1)
}
}