2016-12-04 12:16:11 +00:00
|
|
|
package tsdb
|
|
|
|
|
2016-12-21 14:12:26 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fabxc/tsdb/labels"
|
|
|
|
)
|
2016-12-04 12:16:11 +00: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",
|
|
|
|
}
|
2016-12-21 14:12:26 +00:00
|
|
|
var ls labels.Labels
|
2016-12-04 12:16:11 +00:00
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-12-21 14:12:26 +00:00
|
|
|
ls = labels.FromMap(m)
|
2016-12-04 12:16:11 +00: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",
|
|
|
|
}
|
2016-12-21 14:12:26 +00:00
|
|
|
ls := labels.FromMap(m)
|
2016-12-04 12:16:11 +00: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",
|
|
|
|
}
|
2016-12-21 14:12:26 +00:00
|
|
|
ls := labels.FromMap(m)
|
2016-12-04 12:16:11 +00:00
|
|
|
var res bool
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
res = ls.Equals(ls)
|
|
|
|
}
|
|
|
|
_ = res
|
|
|
|
}
|