VictoriaMetrics/lib/bytesutil/fast_string_transformer_timing_test.go
Aliaksandr Valialkin 17289ff481
lib/regexutil: cache MatchString results for unoptimized regexps
This increases relabeling performance by 3x for unoptimized regexs
2022-09-30 10:41:29 +03:00

32 lines
638 B
Go

package bytesutil
import (
"strings"
"sync/atomic"
"testing"
)
func BenchmarkFastStringTransformer(b *testing.B) {
for _, s := range []string{"", "foo", "foo-bar-baz", "http_requests_total"} {
b.Run(s, func(b *testing.B) {
benchmarkFastStringTransformer(b, s)
})
}
}
func benchmarkFastStringTransformer(b *testing.B, s string) {
fst := NewFastStringTransformer(strings.ToUpper)
b.ReportAllocs()
b.SetBytes(1)
b.RunParallel(func(pb *testing.PB) {
n := uint64(0)
for pb.Next() {
sTransformed := fst.Transform(s)
n += uint64(len(sTransformed))
}
atomic.AddUint64(&GlobalSink, n)
})
}
var GlobalSink uint64