diff --git a/parse_test.go b/parse_test.go index 570f5e1..a31bd5a 100644 --- a/parse_test.go +++ b/parse_test.go @@ -147,28 +147,40 @@ func TestParseString (test *testing.T) { func BenchmarkParseStringLatin (benchmark *testing.B) { benchmark.ReportAllocs() - var meanLen, meanCap int + var rmeanLen, rmeanCap int + var tmeanLen, tmeanCap int for i := 0; i < benchmark.N; i ++ { - runes, _ := parseString(lipsumLt) - meanLen += len(runes) - meanCap += cap(runes) + runes, tokens := parseString(lipsumLt) + rmeanLen += len(runes) + rmeanCap += cap(runes) + tmeanLen += len(tokens) + tmeanCap += cap(tokens) } - meanLen /= benchmark.N - meanCap /= benchmark.N - benchmark.ReportMetric(float64(meanCap) / float64(meanLen), "waste") + rmeanLen /= benchmark.N + rmeanCap /= benchmark.N + tmeanLen /= benchmark.N + tmeanCap /= benchmark.N + benchmark.ReportMetric(float64(rmeanCap) / float64(rmeanLen), "rune-waste") + benchmark.ReportMetric(float64(tmeanCap) / float64(tmeanLen), "token-waste") } func BenchmarkParseStringChinese (benchmark *testing.B) { benchmark.ReportAllocs() - var meanLen, meanCap int + var rmeanLen, rmeanCap int + var tmeanLen, tmeanCap int for i := 0; i < benchmark.N; i ++ { - runes, _ := parseString(lipsumCn) - meanLen += len(runes) - meanCap += cap(runes) + runes, tokens := parseString(lipsumCn) + rmeanLen += len(runes) + rmeanCap += cap(runes) + tmeanLen += len(tokens) + tmeanCap += cap(tokens) } - meanLen /= benchmark.N - meanCap /= benchmark.N - benchmark.ReportMetric(float64(meanCap) / float64(meanLen), "waste") + rmeanLen /= benchmark.N + rmeanCap /= benchmark.N + tmeanLen /= benchmark.N + tmeanCap /= benchmark.N + benchmark.ReportMetric(float64(rmeanCap) / float64(rmeanLen), "rune-waste") + benchmark.ReportMetric(float64(tmeanCap) / float64(tmeanLen), "token-waste") } const lipsumLt =