1
0
mirror of https://github.com/golang/go synced 2024-09-23 23:20:14 -06:00
go/api/next
Joe Tsai bc1d0d8eb1 reflect: add Value.SetZero
The v.SetZero method is a faster equivalent of v.Set(Zero(v.Type())).

Performance:

	                     Direct         CachedZero     NewZero
	SetZero/Bool         2.20ns ± 0%    8.97ns ± 5%    11.4ns ± 1%
	SetZero/Int          3.08ns ± 1%    9.06ns ± 1%    11.5ns ± 0%
	SetZero/Uint         2.88ns ± 1%    9.04ns ± 1%    11.7ns ± 5%
	SetZero/Float        2.65ns ± 2%    9.05ns ± 1%    11.5ns ± 1%
	SetZero/Complex      2.68ns ± 3%    9.31ns ± 1%    11.7ns ± 1%
	SetZero/Array        6.69ns ± 4%    9.32ns ± 1%    11.8ns ± 1%
	SetZero/Chan         3.31ns ± 1%    6.19ns ± 1%    8.20ns ± 1%
	SetZero/Func         3.32ns ± 1%    6.20ns ± 0%    8.24ns ± 1%
	SetZero/Interface    2.66ns ± 1%    9.31ns ± 1%    11.8ns ± 1%
	SetZero/Map          3.31ns ± 1%    6.21ns ± 2%    8.19ns ± 1%
	SetZero/Pointer      3.30ns ± 1%    6.22ns ± 1%    8.17ns ± 1%
	SetZero/Slice        2.90ns ± 4%    9.13ns ± 1%    11.6ns ± 1%
	SetZero/String       3.11ns ± 1%    9.30ns ± 1%    11.8ns ± 2%
	SetZero/Struct       6.37ns ± 1%    9.18ns ± 4%    11.5ns ± 1%

where:

	* Direct is measuring Value.SetZero
	* CachedZero is measuring Value.Set with a cached Zero value
	* NewZero is measuring Value.Set with a new Zero value

Fixes #52376

Change-Id: I793ca723aa97627824c5f5b356b2da30c8e46d71
Reviewed-on: https://go-review.googlesource.com/c/go/+/411476
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Dan Kortschak <dan@kortschak.io>
2022-08-26 17:15:08 +00:00
..
41773.txt net/http: add Server.DisableOptionsHandler for custom handling of OPTIONS * 2022-08-15 18:57:35 +00:00
42537.txt strings, bytes: add CutPrefix and CutSuffix 2022-08-16 19:48:39 +00:00
43620.txt testing: add Elapsed method to testing.B 2022-08-25 17:58:32 +00:00
45038.txt bytes: add Clone function 2022-08-15 19:17:20 +00:00
45899.txt io: add OffsetWriter, NewOffsetWriter 2022-08-19 17:03:55 +00:00
47209.txt path/filepath, io/fs: add SkipAll 2022-08-25 18:50:37 +00:00
51246.txt syscall: add new CLONE_ flags for Linux 2022-08-19 16:12:50 +00:00
51668.txt fmt: add a function to recover the original format string given a State 2022-08-06 09:19:31 +00:00
51896.txt unicode/utf16: add AppendRune 2022-08-19 16:45:08 +00:00
52221.txt crypto/ecdh: new package 2022-08-12 00:03:39 +00:00
52376.txt reflect: add Value.SetZero 2022-08-26 17:15:08 +00:00
52746.txt time: add DateTime, DateOnly, and TimeOnly 2022-08-09 14:33:24 +00:00
53002.txt net/http/httputil: add ReverseProxy.Rewrite 2022-08-16 20:01:36 +00:00
53021.txt crypto/subtle: add XORBytes 2022-08-17 18:47:33 +00:00
53200.txt go/token: add (*FileSet).RemoveFile(*File) method 2022-08-16 16:27:35 +00:00
53346.txt encoding/xml: add (*Encoder).Close 2022-08-23 18:24:30 +00:00
54222.txt debug/elf: add new-style LoongArch reloc types 2022-08-11 19:32:40 +00:00
54251.txt debug/pe: add IMAGE_FILE_MACHINE_RISCV{32,64,128} 2022-08-09 01:21:43 +00:00