bytes.Buffer, I thought you were my friend
Phil Pearl
595
Something to note here, for your particular case you’re correct that concatenating strings is the most efficient, but for anything where you need to append to a buffer in a loop, or if you need to concatenate many more times, bytes.Buffer is going to blow string concatenation out of the water. I ran a few tests of my own on 10k and 100k iterations and got:
63.6231ms (avg) for string concatenation
359.51µs (avg) for appending using bytes.Buffer
On 100k iterations:
5.583221202s
3.468977ms
So don’t stop talking to bytes.Buffer altogether, just make sure you talk to it in the right situations.