mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
86394b4179
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
22 lines
530 B
Go
22 lines
530 B
Go
package discoveryutils
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkSanitizeLabelName(b *testing.B) {
|
|
labelName := "foo-bar/baz/aaaa+bbb"
|
|
expectedLabelNameSanitized := "foo_bar_baz_aaaa_bbb"
|
|
b.SetBytes(1)
|
|
b.ReportAllocs()
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
labelNameSanitized := SanitizeLabelName(labelName)
|
|
if labelNameSanitized != expectedLabelNameSanitized {
|
|
panic(fmt.Errorf("unexpected sanitized label name; got %q; want %q", labelNameSanitized, expectedLabelNameSanitized))
|
|
}
|
|
}
|
|
})
|
|
}
|