fix(tests): add ac benchmark

This commit is contained in:
Łukasz Mierzwa
2023-07-27 17:50:38 +01:00
committed by Łukasz Mierzwa
parent 45029bcdc9
commit c9c9f079ae

View File

@@ -1,6 +1,7 @@
package filters_test
import (
"fmt"
"sort"
"testing"
@@ -143,3 +144,26 @@ func TestBuildAutocomplete(t *testing.T) {
}
}
}
func BenchmarkAutocomplete(b *testing.B) {
const n = 10000
alerts := make([]models.Alert, 0, n)
for i := 0; i < n; i++ {
alerts = append(alerts, models.Alert{
State: models.AlertStateActive,
Labels: models.Labels{
{Name: "foo", Value: fmt.Sprintf("xxx%d", i)},
{Name: "number", Value: fmt.Sprintf("%d", i)},
},
Receiver: fmt.Sprintf("receiver-%d", i%1000),
Alertmanager: []models.AlertmanagerInstance{
{Cluster: "cluster", Name: "am1"},
{Cluster: "cluster", Name: "am2"},
},
})
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
filters.BuildAutocomplete(alerts)
}
}