Benchmarks report len, cap, and waste of runes slice
This commit is contained in:
parent
013b121d46
commit
cde84b8756
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user