tcnksm / go-httpstat

Tracing golang HTTP request latency
MIT License
423 stars 72 forks source link

Reduce cpu, memory, and allocations in formatter #15

Closed billf closed 1 year ago

billf commented 7 years ago

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

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%