bytes.Buffer, I thought you were my friend
Phil Pearl
595
It may be worth looking at the Reset method on bytes.Buffer.
[Go] import ( "bytes" "testing" ) var ( itemType = "item-type" clientID = - Pastebin.com
Pastebin PRO Accounts AUTUMN SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account! Offer Ends…pastebin.com
Pastebin PRO Accounts AUTUMN SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account! Offer Ends…pastebin.com
In those benchmarks, I get these results:
BenchmarkStringPlus-8 20000000 64.3 ns/op 32 B/op 1 allocs/op
BenchmarkByteBufReset-8 20000000 90.3 ns/op 32 B/op 1 allocs/op
While the + method is faster, bytes.Buffer is more flexible, and you’re not incurring huge allocation overhead with it if you use Reset.