go
go copied to clipboard
time: optimize the performance of the function appendFormatRFC3339
Use AppendIntWidth4 instead of AppendInt to handle year Use AppendIntWidth2 instead of AppendInt to handle month, day, hour, minute, and second
Benchmark results: goos: windows goarch: amd64 pkg: time cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
│ Before │ After │
│ sec/op │ sec/op vs base │
TimeFormatRFC3339-12 40.91n ± 1% 25.47n ± 7% -37.74% (p=0.000 n=10)
│ AppendInt │ AppendIntWidth4 │
│ sec/op │ sec/op vs base │
AppendIntWidth4 4.973n ± 0% 3.541n ± 1% -28.80% (p=0.000 n=10)