go-httpstat
go-httpstat copied to clipboard
Reduce cpu, memory, and allocations in formatter
adds a benchmark for both %v and %+v.
reduces cpu, memory, and allocations in the formatting code itself.
-
%+vwrite directly tofmt.Stateas it is itself anio.Writer -
%vreduce memory by avoiding[]stringandstrings.Joinwith abytes.Buffer
benchcmp output:
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%