mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
30 lines
529 B
Go
30 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)
|
||
|
})
|
||
|
}
|