This module benchmarks joining 5 strings with colons and writing the resulting string to a buffer. The result shows that concatenating with +
is ~3-4x faster and performs fewer allocations. Fprintf
and friends require 1 allocation per formatting operator.
go test -bench=.
goos: darwin
goarch: arm64
pkg: bench-strings
BenchmarkFprintf-10 5534516 216.9 ns/op 192 B/op 7 allocs/op
BenchmarkConcat-10 19905655 60.62 ns/op 64 B/op 1 allocs/op
PASS
ok bench-strings 2.827s