lestrrat-go / strftime

Fast strftime for Go
MIT License
110 stars 21 forks source link

Add FormatBuffer #26

Closed ianwilkes closed 3 years ago

ianwilkes commented 3 years ago

As discussed in issue 25, this is structurally similar to the standard library's AppendFormat method. I also fixed some issues with BenchmarkLestrratCachedWriter which made it look slower than it really was.

Nets about a 15% speedup which is less than I was hoping for, but still worth using in performance-intensive situations. Note the difference in the time output though - FormatBuffer uses about 20% less CPU time in total for the same number of executions, probably due to reduced garbage collection overhead.

[master][~/hound/go/src/github.com/ianwilkes/strftime/bench]$ time gotest . -bench BenchmarkLestrratCachedWriter -benchtime 30000000x
goos: darwin
goarch: amd64
pkg: github.com/lestrrat-go/strftime/bench
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkLestrratCachedWriter-8     30000000         390.1 ns/op
PASS
ok    github.com/lestrrat-go/strftime/bench 11.856s
gotest . -bench BenchmarkLestrratCachedWriter -benchtime 30000000x  12.69s user 1.07s system 111% cpu 12.299 total

[master][~/hound/go/src/github.com/ianwilkes/strftime/bench]$ time gotest . -bench BenchmarkLestrratCachedFormatBuffer -benchtime 30000000x
goos: darwin
goarch: amd64
pkg: github.com/lestrrat-go/strftime/bench
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkLestrratCachedFormatBuffer-8     30000000         330.3 ns/op
PASS
ok    github.com/lestrrat-go/strftime/bench 10.063s
gotest . -bench BenchmarkLestrratCachedFormatBuffer -benchtime 30000000x  10.49s user 0.62s system 105% cpu 10.517 total
codecov-commenter commented 3 years ago

Codecov Report

Merging #26 (50bb69c) into master (09329cc) will increase coverage by 1.58%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
+ Coverage   77.73%   79.32%   +1.58%     
==========================================
  Files           5        5              
  Lines         265      266       +1     
==========================================
+ Hits          206      211       +5     
+ Misses         41       38       -3     
+ Partials       18       17       -1     
Impacted Files Coverage Δ
strftime.go 86.20% <100.00%> (+2.48%) :arrow_up:
appenders.go 82.07% <0.00%> (+1.88%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 09329cc...50bb69c. Read the comment docs.

lestrrat commented 3 years ago

Nice, thanks