← All benchmarksGo

Go strings.Builder vs +=: 0.18 ms vs 163.9 ms, 21 vs 50,097 allocations

Is strings.Builder faster than string concatenation in Go?

Yes. Building a 50,000-character string took 163.9 ms, 1.35 GB of allocations and 50,097 allocs with +=, versus 0.18 ms, 212 KB and 21 allocs with strings.Builder in go test -bench.

Results

s += "x" (50,000 appends)163.9 ms/op, 1.35 GB/op, 50,097 allocs/op
strings.Builder (50,000 appends)0.18 ms/op, 212 KB/op, 21 allocs/op

How it was measured

go test -bench with 5 iterations, 50,000 single-character appends.

s := ""
for i := 0; i < 50_000; i++ { s += "x" }

var sb strings.Builder
for i := 0; i < 50_000; i++ { sb.WriteString("x") }

Why

Go strings are immutable, so += allocates a new string each time. strings.Builder grows a single byte buffer.

When this does not apply

A handful of concatenations outside hot loops do not matter. Benchmark before optimizing.

Environment

MacBook Air (Apple silicon, 8 cores), macOS, Go 1.22. Measured 2026-10-12.

Source: shorts/demo-ticket/w3/gob/gob_test.go in my content-engine repository. Treat any single run as a direction; re-run it on your hardware.

Related

By Josué Barros, senior software engineer (full-stack, data and AI).