VictoriaMetrics/lib/promscrape/discoveryutils/internstring_timing_test.go
Aliaksandr Valialkin c06e7a142c
lib/promscrape: optimize discoveryutils.SanitizeLabelName()
Cache sanitized label names and return them next time.
This reduces the number of allocations and speeds up the SanitizeLabelName()
function for common case when the number of unique label names is smaller than 100k
2022-08-27 00:17:45 +03:00

25 lines
468 B
Go

package discoveryutils
import (
"fmt"
"testing"
)
func BenchmarkInternString(b *testing.B) {
a := make([]string, 10000)
for i := range a {
a[i] = fmt.Sprintf("string_%d", i)
}
b.ReportAllocs()
b.SetBytes(int64(len(a)))
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
for _, s := range a {
sResult := InternString(s)
if sResult != s {
panic(fmt.Sprintf("unexpected string obtained; got %q; want %q", sResult, s))
}
}
}
})
}