chore(benchmarks): use b.Loop() BE-12182 (#1072)

pull/12341/merge
andres-portainer 2025-08-20 12:54:26 -03:00 committed by GitHub
parent 89f5a20786
commit 30aba86380
2 changed files with 8 additions and 17 deletions

View File

@ -189,9 +189,7 @@ func BenchmarkFilterEndpointsBySearchCriteria_PartialMatch(b *testing.B) {
searchString := "edge-group"
b.ResetTimer()
for range b.N {
for b.Loop() {
e := filterEndpointsBySearchCriteria(endpoints, endpointGroups, edgeGroups, tagsMap, searchString)
if len(e) != n {
b.FailNow()
@ -237,13 +235,9 @@ func BenchmarkFilterEndpointsBySearchCriteria_FullMatch(b *testing.B) {
searchString := "edge-group"
b.ResetTimer()
for range b.N {
for b.Loop() {
e := filterEndpointsBySearchCriteria(endpoints, endpointGroups, edgeGroups, tagsMap, searchString)
if len(e) != n {
b.FailNow()
}
require.Len(b, e, n)
}
}

View File

@ -4,6 +4,8 @@ import (
"testing"
"github.com/portainer/portainer/api/slicesx"
"github.com/stretchr/testify/require"
)
func Test_Filter(t *testing.T) {
@ -60,12 +62,9 @@ func Benchmark_Filter(b *testing.B) {
source[i] = i
}
b.ResetTimer()
for range b.N {
for b.Loop() {
e := slicesx.Filter(source, func(x int) bool { return x%2 == 0 })
if len(e) != n/2 {
b.FailNow()
}
require.Len(b, e, n/2)
}
}
@ -89,8 +88,6 @@ func Benchmark_FilterInPlace(b *testing.B) {
b.ResetTimer()
for i := range b.N {
e := slicesx.FilterInPlace(copies[i], func(x int) bool { return x%2 == 0 })
if len(e) != n/2 {
b.FailNow()
}
require.Len(b, e, n/2)
}
}