From cde84b8756a62af7d76c7594f0ddb407fe249535 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 19 Sep 2024 09:18:11 -0400 Subject: [PATCH] Benchmarks report len, cap, and waste of runes slice --- parse_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/parse_test.go b/parse_test.go index 0201c57..365a5ab 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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 =