labels: extend benchmark for Has()

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-08-13 14:55:50 +01:00
parent 657da2eb98
commit 33aab1b2cc

View file

@ -472,16 +472,22 @@ func BenchmarkLabels_Get(b *testing.B) {
for _, scenario := range []struct { for _, scenario := range []struct {
desc, label string desc, label string
}{ }{
{"get first label", allLabels[0].Name}, {"first label", allLabels[0].Name},
{"get middle label", allLabels[size/2].Name}, {"middle label", allLabels[size/2].Name},
{"get last label", allLabels[size-1].Name}, {"last label", allLabels[size-1].Name},
{"get not-found label", "benchmark"}, {"not-found label", "benchmark"},
} { } {
b.Run(scenario.desc, func(b *testing.B) { b.Run(scenario.desc, func(b *testing.B) {
b.ResetTimer() b.Run("get", func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = labels.Get(scenario.label) _ = labels.Get(scenario.label)
} }
})
b.Run("has", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = labels.Has(scenario.label)
}
})
}) })
} }
}) })