-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Milestone
Description
When I run the attached benchmark, I expected that accessing the array would be faster in all scenarios. In Go 1.0, the speeds are equal. However, in Go 1.1 (tip), it seems that array access time regressed significantly for global arrays (by about 20%). Following a response from Russ and Rob (see https://groups.google.com/d/msg/golang-dev/TI54OYWno68/J-fKuTFVG_wJ), I've verified that array access speed is better when the array is local to the function or a field in a local struct value. For global arrays, there's still a significant slowdown. Using a pointer to the global array didn't seem to make a difference. arrlen: 1024 BenchmarkArrayGlobal 2000000 860 ns/op BenchmarkArrayGlobalPtr 2000000 872 ns/op BenchmarkSliceGlobal 5000000 741 ns/op BenchmarkArrayLocal 2000000 862 ns/op BenchmarkSliceLocal 2000000 941 ns/op BenchmarkArrayStructField 1000000 1090 ns/op BenchmarkSliceStructField 1000000 1249 ns/op arrlen: 2048 BenchmarkArrayGlobal 1000000 1742 ns/op BenchmarkArrayGlobalPtr 1000000 1738 ns/op BenchmarkSliceGlobal 1000000 1454 ns/op BenchmarkArrayLocal 1000000 1734 ns/op BenchmarkSliceLocal 1000000 1836 ns/op BenchmarkArrayStructField 1000000 2160 ns/op BenchmarkSliceStructField 1000000 2488 ns/op Please run attached benchmark to reproduce. Which compiler are you using (5g, 6g, 8g, gccgo)? 6g Which operating system are you using? Linux 3.5.0-26-generic #42-Ubuntu SMP x86_64 GNU/Linux Which version are you using? (run 'go version') go version devel +c246dbf446db Wed Mar 20 23:53:38 2013 -0400 linux/amd64
Attachments:
- array_vs_slice_test.go (1788 bytes)