Benchmarks report len, cap, and waste of runes slice

This commit is contained in:
Sasha Koshka 2024-09-19 09:18:11 -04:00
parent 013b121d46
commit cde84b8756

View File

@ -147,16 +147,32 @@ func TestParseString (test *testing.T) {
func BenchmarkParseStringLatin (benchmark *testing.B) {
benchmark.ReportAllocs()
var meanLen, meanCap int
for i := 0; i < benchmark.N; i ++ {
parseString(lipsumLt)
runes, _ := parseString(lipsumLt)
meanLen += len(runes)
meanCap += cap(runes)
}
meanLen /= benchmark.N
meanCap /= benchmark.N
benchmark.ReportMetric(float64(meanLen), "len")
benchmark.ReportMetric(float64(meanCap), "cap")
benchmark.ReportMetric(float64(meanCap - meanLen), "waste")
}
func BenchmarkParseStringChinese (benchmark *testing.B) {
benchmark.ReportAllocs()
var meanLen, meanCap int
for i := 0; i < benchmark.N; i ++ {
parseString(lipsumCn)
runes, _ := parseString(lipsumCn)
meanLen += len(runes)
meanCap += cap(runes)
}
meanLen /= benchmark.N
meanCap /= benchmark.N
benchmark.ReportMetric(float64(meanLen), "len")
benchmark.ReportMetric(float64(meanCap), "cap")
benchmark.ReportMetric(float64(meanCap - meanLen), "waste")
}
const lipsumLt =