]> Cypherpunks.ru repositories - gostls13.git/commit
time: optimize appendInt and appendNanos
authorJoe Tsai <joetsai@digital-static.net>
Sun, 25 Sep 2022 06:40:02 +0000 (23:40 -0700)
committerJoseph Tsai <joetsai@digital-static.net>
Mon, 24 Oct 2022 19:23:32 +0000 (19:23 +0000)
commit7f04b8416297a3810cd2eddbcce84ac569e9b96d
tree6c8d373e008cc8580cfd98416752831cc489c604
parentf841722853db7911cb5f65d1045e9ecbb5a0d08c
time: optimize appendInt and appendNanos

The appendInt function previously performed a double pass
over the formatted integer. We can avoid the second pass
if we knew the exact length of formatted integer,
allowing us to directly serialize into the output buffer.

Rename formatNano to appendNano to be consistent with
other append-like functionality.

Performance:

name               old time/op  new time/op  delta
FormatRFC3339Nano  109ns ± 1%   72ns ± 1%    -34.06%  (p=0.000 n=10+10)

Change-Id: Id48f77eb4976fb1dcd6e27fb6a02d29cbf0c026a
Reviewed-on: https://go-review.googlesource.com/c/go/+/444278
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/time/export_test.go
src/time/format.go
src/time/format_rfc3339.go
src/time/format_test.go