funcBenchmarkSprintf(b *testing.B) { b.ResetTimer() for idx := 0; idx < b.N; idx++ { var s string for i := 0; i < numbers; i++ { s = fmt.Sprintf("%v%v", s, i) } } b.StopTimer() }
funcBenchmarkStringBuilder(b *testing.B) { b.ResetTimer() for idx := 0; idx < b.N; idx++ { var builder strings.Builder for i := 0; i < numbers; i++ { builder.WriteString(strconv.Itoa(i))
} _ = builder.String() } b.StopTimer() }
funcBenchmarkBytesBuf(b *testing.B) { b.ResetTimer() for idx := 0; idx < b.N; idx++ { var buf bytes.Buffer for i := 0; i < numbers; i++ { buf.WriteString(strconv.Itoa(i)) } _ = buf.String() } b.StopTimer() }
funcBenchmarkStringAdd(b *testing.B) { b.ResetTimer() for idx := 0; idx < b.N; idx++ { var s string for i := 0; i < numbers; i++ { s += strconv.Itoa(i) }