2016-12-04 04:16:11 -08:00
|
|
|
package tsdb
|
|
|
|
|
2016-12-21 06:12:26 -08:00
|
|
|
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",
|
|
|
|
}
|
2016-12-21 06:12:26 -08:00
|
|
|
var ls labels.Labels
|
2016-12-04 04:16:11 -08:00
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-12-21 06:12:26 -08:00
|
|
|
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",
|
|
|
|
}
|
2016-12-21 06:12:26 -08:00
|
|
|
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",
|
|
|
|
}
|
2016-12-21 06:12:26 -08:00
|
|
|
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
|
|
|
|
}
|