The target is of type *buffer.Bytes and the buffer
is simply written to it.
fmt.Fprint
Write()
method of buffer package with a conversion tobytes
WriteTo()
method of buffer packageio.CopyBuffer()
As fmt
offers more possibilities, it is about 6x heavier than the fastest alternate solution.
The byte conversion keeps the buffer to copy intact and other methods are thus heavier because
it must be re-filled.
This benchmark is irrelevant if any formatting occurs during writing.
>go test -bench=. ./src/writebuffer
Results
go version go1.12.6 windows/amd64
pkg: github.com/iWdGo/GoCompilerEfficiency/src/writebuffer
BenchmarkWriteBuffer-4 3000000 481 ns/op
BenchmarkWriteToBuffer-4 1000000 1745 ns/op
BenchmarkIoCopyBuffer-4 1000000 2304 ns/op
BenchmarkFmtWriteBuffer-4 500000 3783 ns/op
PASS