1
0
mirror of https://github.com/golang/go synced 2024-10-03 04:21:22 -06:00
go/src/cmd
Josh Bleecher Snyder 4bc9badd75 cmd/internal/gc: speed up large string switches
Switch statements do a binary search on long runs of constants.
Doing a less-than comparison on a string is much more expensive
than on (say) an int. Use two part comparison for strings:
First compare length, then the strings themselves.

Benchmarks from issue 10000:

benchmark                  old ns/op     new ns/op     delta
BenchmarkIf0               3.36          3.35          -0.30%
BenchmarkIf1               4.45          4.47          +0.45%
BenchmarkIf2               5.22          5.26          +0.77%
BenchmarkIf3               5.56          5.58          +0.36%
BenchmarkIf4               10.5          10.6          +0.95%
BenchmarkIfNewStr0         5.26          5.30          +0.76%
BenchmarkIfNewStr1         7.19          7.15          -0.56%
BenchmarkIfNewStr2         7.23          7.16          -0.97%
BenchmarkIfNewStr3         7.47          7.43          -0.54%
BenchmarkIfNewStr4         12.4          12.2          -1.61%
BenchmarkSwitch0           9.56          4.24          -55.65%
BenchmarkSwitch1           8.64          5.58          -35.42%
BenchmarkSwitch2           9.38          10.1          +7.68%
BenchmarkSwitch3           8.66          5.00          -42.26%
BenchmarkSwitch4           7.99          8.18          +2.38%
BenchmarkSwitchNewStr0     11.3          6.12          -45.84%
BenchmarkSwitchNewStr1     11.1          8.33          -24.95%
BenchmarkSwitchNewStr2     11.0          11.1          +0.91%
BenchmarkSwitchNewStr3     10.3          6.93          -32.72%
BenchmarkSwitchNewStr4     11.0          11.2          +1.82%

Fixes #10000

Change-Id: Ia2fffc32e9843425374c274064f709ec7ee46d80
Reviewed-on: https://go-review.googlesource.com/7698
Reviewed-by: Keith Randall <khr@golang.org>
2015-03-18 21:38:40 +00:00
..
5g cmd/...: remove use of func() { ... }() in loop increment 2015-03-17 00:34:00 +00:00
5l cmd/5l: make 5l work on openbsd 2015-03-13 02:51:12 +00:00
6g cmd/6g: make proginfo register bits constants 2015-03-17 01:24:40 +00:00
6l cmd/5l etc: restore comments lost during C -> Go conversion 2015-03-05 21:49:39 +00:00
7g cmd/7g: add ARM64 Go compiler, based on 9g 2015-03-16 18:45:26 +00:00
7l cmd/7l: add the ARM64 linker 2015-03-16 18:45:16 +00:00
8g cmd/internal/gc, etc: remove canemitecode of Naddr 2015-03-13 22:56:42 +00:00
8l all: remove dragonfly/386 port 2015-03-14 10:47:19 +00:00
9g cmd/internal/gc, etc: remove canemitecode of Naddr 2015-03-13 22:56:42 +00:00
9l cmd/...: remove use of func() { ... }() in loop increment 2015-03-17 00:34:00 +00:00
addr2line cmd/addr2line: exclude Go tool test on darwin/arm 2015-02-26 23:06:30 +00:00
api Revert "cmd/api: treat a hex-y VERSION as devel and permit API changes" 2015-02-08 20:44:22 +00:00
asm cmd/asm: add support for ARM64 2015-03-16 18:45:08 +00:00
cgo all: use "reports whether" in place of "returns true if(f)" 2015-03-18 15:14:06 +00:00
dist cmd/dist: show reason for command failure 2015-03-17 00:30:50 +00:00
fix all: use "reports whether" in place of "returns true if(f)" 2015-03-18 15:14:06 +00:00
go all: use "reports whether" in place of "returns true if(f)" 2015-03-18 15:14:06 +00:00
gofmt all: use "reports whether" in place of "returns true if(f)" 2015-03-18 15:14:06 +00:00
internal cmd/internal/gc: speed up large string switches 2015-03-18 21:38:40 +00:00
link debug/goobj: move to cmd/internal/goobj 2014-11-16 20:52:45 -05:00
nm cmd/nm: exclude Go tool test on darwin/arm 2015-02-26 23:07:27 +00:00
objdump cmd/objdump: disable TestDisasm.* on arm64 2015-03-16 18:46:52 +00:00
old5a all: mv 5a old5a and so on 2015-03-02 00:14:11 +00:00
old6a cmd/internal/obj/x86: accept TYPE_MEM in CMPPS 3rd argument 2015-03-05 04:59:35 +00:00
old8a cmd/8g, cmd/old8a: stop renaming x86 import to i386 2015-03-05 06:06:54 +00:00
old9a all: mv 5a old5a and so on 2015-03-02 00:14:11 +00:00
pack cmd/pack: skip fork test on darwin/arm 2015-03-01 01:27:06 +00:00
pprof cmd/pprof/internal/profile: insert blank line after non-doc comment 2015-03-16 23:07:15 +00:00
trace cmd/trace: move goroutine analysis code to internal/trace 2015-03-11 12:53:24 +00:00
yacc cmd/yacc: fix path in documentation 2015-03-17 04:53:21 +00:00