mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-20 23:46:23 +01:00
17289ff481
This increases relabeling performance by 3x for unoptimized regexs
32 lines
638 B
Go
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
|