1
0
mirror of https://github.com/golang/go synced 2024-10-05 21:21:21 -06:00
go/src/time
Justin Nuß 5f859ba83d time: Use AppendFormat in Marshal[Text|JSON]
The current implementations of MarshalJSON and MarshalText use
time.Format which returns a string (converted from a byte slice),
only to convert it back to a byte slice.

Avoid the conversion (and thus an allocation) by directly appending
the formatted time to a preallocated byte slice, using the new
AppendFormat function, introduced in golang.org/cl/1760.

This reduces the allocations done in Marshal[Text|JSON] by 50%.

benchmark                old ns/op     new ns/op     delta
BenchmarkMarshalJSON     626           507           -19.01%
BenchmarkMarshalText     598           511           -14.55%

benchmark                old allocs     new allocs     delta
BenchmarkMarshalJSON     2              1              -50.00%
BenchmarkMarshalText     2              1              -50.00%

benchmark                old bytes     new bytes     delta
BenchmarkMarshalJSON     96            48            -50.00%
BenchmarkMarshalText     96            48            -50.00%

Fixes #11025

Change-Id: I468f78d075a6ecc1cdc839df7fb407fbc6ff2e70
Reviewed-on: https://go-review.googlesource.com/10555
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-22 11:31:58 +00:00
..
example_test.go time: add a thorough example for time.Format 2015-03-26 18:44:42 +00:00
export_test.go
export_windows_test.go time: fix registry zone info lookup on Windows 2015-05-12 14:28:40 +00:00
format_test.go
format.go time: make it clearer how to format a fractional second 2015-07-15 05:13:05 +00:00
genzabbrs.go
internal_test.go
sleep_test.go time: deflake TestAfterQueuing 2015-05-06 19:26:27 +00:00
sleep.go time: panic with a more helpful error on use of invalid Timer 2014-10-21 13:26:40 +02:00
sys_plan9.go
sys_unix.go time: return informative errors when failing to load timezone data. 2015-02-08 22:20:37 +00:00
sys_windows.go
tick_test.go
tick.go time: document that time.Tick creates an unrecoverable resource 2015-07-13 01:35:36 +00:00
time_test.go time: Use AppendFormat in Marshal[Text|JSON] 2015-08-22 11:31:58 +00:00
time.go time: Use AppendFormat in Marshal[Text|JSON] 2015-08-22 11:31:58 +00:00
zoneinfo_abbrs_windows.go
zoneinfo_ios.go time: zoneinfo support for darwin 2015-03-03 15:37:14 +00:00
zoneinfo_plan9.go Build fix for plan9 after 8bf13838eb. 2015-02-08 22:30:46 +00:00
zoneinfo_read.go
zoneinfo_test.go
zoneinfo_unix.go time: zoneinfo support for darwin 2015-03-03 15:37:14 +00:00
zoneinfo_windows_test.go time: fix registry zone info lookup on Windows 2015-05-12 14:28:40 +00:00
zoneinfo_windows.go time: fix registry zone info lookup on Windows 2015-05-12 14:28:40 +00:00
zoneinfo.go