| 1142 | } |
| 1143 | |
| 1144 | func BenchmarkGetLabels_MediumSet(b *testing.B) { |
| 1145 | m := prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 1146 | Name: "test", |
| 1147 | ConstLabels: map[string]string{ |
| 1148 | "cluster": "abc", |
| 1149 | }, |
| 1150 | }, []string{"reason", "user"}) |
| 1151 | |
| 1152 | for i := 1; i <= 1000; i++ { |
| 1153 | m.WithLabelValues("bad", fmt.Sprintf("user%d", i)).Inc() |
| 1154 | m.WithLabelValues("worse", fmt.Sprintf("user%d", i)).Inc() |
| 1155 | m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc() |
| 1156 | |
| 1157 | if i%2 == 0 { |
| 1158 | m.WithLabelValues("bad", fmt.Sprintf("user%d", i)).Inc() |
| 1159 | m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc() |
| 1160 | } else { |
| 1161 | m.WithLabelValues("worst", fmt.Sprintf("user%d", i)).Inc() |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | for b.Loop() { |
| 1166 | if _, err := GetLabels(m, map[string]string{"user": "user1", "reason": "worse"}); err != nil { |
| 1167 | b.Fatal(err) |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | func TestGetLabels(t *testing.T) { |
| 1173 | m := prometheus.NewCounterVec(prometheus.CounterOpts{ |