VictoriaMetrics/lib/stringsutil/less_natural_timing_test.go
Aliaksandr Valialkin 09e81cb5aa
wip
2024-05-13 15:59:25 +02:00

29 lines
529 B
Go

package stringsutil
import (
"testing"
)
func BenchmarkLessNatural(b *testing.B) {
b.Run("distinct_string_prefixes", func(b *testing.B) {
benchmarkLessNatural(b, []string{
"aaa", "bbb", "ccc", "ddd", "eee", "fff",
})
})
}
func benchmarkLessNatural(b *testing.B, a []string) {
b.ReportAllocs()
b.SetBytes(int64(len(a) - 1))
b.RunParallel(func(pb *testing.PB) {
n := uint64(0)
for pb.Next() {
for i := 1; i < len(a); i++ {
if LessNatural(a[i-1], a[i]) {
n++
}
}
}
GlobalSink.Add(n)
})
}