diff --git a/test/labels_test.go b/test/labels_test.go index bc54b4459..14f85a672 100644 --- a/test/labels_test.go +++ b/test/labels_test.go @@ -5,9 +5,52 @@ import ( "crypto/rand" "testing" - "github.com/fabxc/tsdb" + "github.com/fabxc/tsdb/labels" ) +func BenchmarkMapClone(b *testing.B) { + m := map[string]string{ + "job": "node", + "instance": "123.123.1.211:9090", + "path": "/api/v1/namespaces//deployments/", + "method": "GET", + "namespace": "system", + "status": "500", + "prometheus": "prometheus-core-1", + "datacenter": "eu-west-1", + "pod_name": "abcdef-99999-defee", + } + + for i := 0; i < b.N; i++ { + res := make(map[string]string, len(m)) + for k, v := range m { + res[k] = v + } + m = res + } +} + +func BenchmarkLabelsClone(b *testing.B) { + m := map[string]string{ + "job": "node", + "instance": "123.123.1.211:9090", + "path": "/api/v1/namespaces//deployments/", + "method": "GET", + "namespace": "system", + "status": "500", + "prometheus": "prometheus-core-1", + "datacenter": "eu-west-1", + "pod_name": "abcdef-99999-defee", + } + l := labels.LabelsFromMap(m) + + for i := 0; i < b.N; i++ { + res := make(labels.Labels, len(l)) + copy(res, l) + l = res + } +} + func BenchmarkLabelMapAccess(b *testing.B) { m := map[string]string{ "job": "node", @@ -46,7 +89,7 @@ func BenchmarkLabelSetAccess(b *testing.B) { "datacenter": "eu-west-1", "pod_name": "abcdef-99999-defee", } - ls := tsdb.LabelsFromMap(m) + ls := labels.LabelsFromMap(m) var v string