prometheus/db_test.go

67 lines
1.3 KiB
Go
Raw Normal View History

2016-12-04 04:16:11 -08:00
package tsdb
import (
"testing"
"github.com/fabxc/tsdb/labels"
)
2016-12-04 04:16:11 -08:00
func BenchmarkLabelSetFromMap(b *testing.B) {
m := map[string]string{
"job": "node",
"instance": "123.123.1.211:9090",
"path": "/api/v1/namespaces/<namespace>/deployments/<name>",
"method": "GET",
"namespace": "system",
"status": "500",
}
var ls labels.Labels
2016-12-04 04:16:11 -08:00
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ls = labels.FromMap(m)
2016-12-04 04:16:11 -08:00
}
_ = ls
}
func BenchmarkMapFromLabels(b *testing.B) {
m := map[string]string{
"job": "node",
"instance": "123.123.1.211:9090",
"path": "/api/v1/namespaces/<namespace>/deployments/<name>",
"method": "GET",
"namespace": "system",
"status": "500",
}
ls := labels.FromMap(m)
2016-12-04 04:16:11 -08:00
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m = ls.Map()
}
}
func BenchmarkLabelSetEquals(b *testing.B) {
// The vast majority of comparisons will be against a matching label set.
m := map[string]string{
"job": "node",
"instance": "123.123.1.211:9090",
"path": "/api/v1/namespaces/<namespace>/deployments/<name>",
"method": "GET",
"namespace": "system",
"status": "500",
}
ls := labels.FromMap(m)
2016-12-04 04:16:11 -08:00
var res bool
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
res = ls.Equals(ls)
}
_ = res
}