-
Notifications
You must be signed in to change notification settings - Fork 113
/
prometheus_test.go
63 lines (51 loc) · 1.3 KB
/
prometheus_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"testing"
"github.com/prometheus/common/model"
)
// go test -bench='BenchmarkPrometheus*' -count=5 | tee BenchmarkPrometheus
func BenchmarkPrometheusConvertLabelSet(b *testing.B) {
metric := model.Metric{}
for i := 0; i < 99; i++ {
metric[model.LabelName(fmt.Sprintf("foo%d", i))] = model.LabelValue(fmt.Sprintf("bar%d", i))
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
convertLabelSet(metric)
}
}
func BenchmarkPrometheusConvertVector(b *testing.B) {
vector := []*model.Sample{{
Metric: model.Metric{"foo0": "bar0", "foo1": "bar1", "foo2": "bar2"},
Timestamp: 1669152132000,
Value: 1,
}, {
Metric: model.Metric{"foo0": "bar0", "foo1": "bar1", "foo3": "bar3"},
Timestamp: 1669152132000,
Value: 1,
}, {
Metric: model.Metric{"foo0": "bar0", "foo1": "bar1", "foo4": "bar4"},
Timestamp: 1669152132000,
Value: 1,
}}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
convertVector(vector)
}
}
func BenchmarkPrometheusConvertMatrix(b *testing.B) {
sp := make([]model.SamplePair, 4_000)
for i := 0; i < 4_000; i++ {
sp[i].Timestamp = model.Time(i)
sp[i].Value = model.SampleValue(i)
}
m := model.Matrix{{Values: sp}}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
convertMatrix(m)
}
}