VictoriaMetrics/lib/bytesutil/internstring_timing_test.go
Aliaksandr Valialkin 593da3603e
lib/bytesutil: move InternString() from lib/promscrape/discoverytutils to lib/bytesutil
lib/bytesutil is more appropriate place for InternString() function
2022-09-30 07:44:35 +03:00

26 lines
463 B
Go

package bytesutil
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))
}
}
}
})
}