Closed billf closed 1 year ago
adds a benchmark for both %v and %+v. reduces cpu, memory, and allocations in the formatting code itself.
%v
%+v
fmt.State
io.Writer
[]string
strings.Join
bytes.Buffer
benchcmp output:
benchcmp
benchmark old ns/op new ns/op delta BenchmarkHTTPStat_Formatter/%+v-8 2652 2053 -22.59% BenchmarkHTTPStat_Formatter/%v-8 4347 2786 -35.91% benchmark old allocs new allocs delta BenchmarkHTTPStat_Formatter/%+v-8 16 11 -31.25% BenchmarkHTTPStat_Formatter/%v-8 37 16 -56.76% benchmark old bytes new bytes delta BenchmarkHTTPStat_Formatter/%+v-8 1697 560 -67.00% BenchmarkHTTPStat_Formatter/%v-8 2309 1532 -33.65%
adds a benchmark for both
%v
and%+v
. reduces cpu, memory, and allocations in the formatting code itself.%+v
write directly tofmt.State
as it is itself anio.Writer
%v
reduce memory by avoiding[]string
andstrings.Join
with abytes.Buffer
benchcmp
output: