go-httpstat icon indicating copy to clipboard operation
go-httpstat copied to clipboard

Reduce cpu, memory, and allocations in formatter

Open billf opened this issue 8 years ago • 0 comments

adds a benchmark for both %v and %+v. reduces cpu, memory, and allocations in the formatting code itself.

  • %+v write directly to fmt.State as it is itself an io.Writer
  • %v reduce memory by avoiding []string and strings.Join with a bytes.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%

billf avatar Aug 17 '17 03:08 billf