MCPcopy
hub / github.com/prometheus/client_golang / benchmarkMetricVecWithLabelValues

Function benchmarkMetricVecWithLabelValues

prometheus/vec_test.go:980–1006  ·  view source on GitHub ↗
(b *testing.B, labels map[string][]string)

Source from the content-addressed store, hash-verified

978}
979
980func benchmarkMetricVecWithLabelValues(b *testing.B, labels map[string][]string) {
981 var keys []string
982 for k := range labels { // Map order dependent, who cares though.
983 keys = append(keys, k)
984 }
985
986 values := make([]string, len(labels)) // Value cache for permutations.
987 vec := NewGaugeVec(
988 GaugeOpts{
989 Name: "test",
990 Help: "helpless",
991 },
992 keys,
993 )
994
995 b.ReportAllocs()
996 b.ResetTimer()
997 for i := 0; i < b.N; i++ {
998 // Varies input across provide map entries based on key size.
999 for j, k := range keys {
1000 candidates := labels[k]
1001 values[j] = candidates[i%len(candidates)]
1002 }
1003
1004 vec.WithLabelValues(values...)
1005 }
1006}

Calls 2

WithLabelValuesMethod · 0.95
NewGaugeVecFunction · 0.70

Tested by

no test coverage detected