[go-nuts] Re: Accessing an slice is too slow than Array

2017-01-05 Thread Dave Cheney
and at the end of the day, the difference per access is 1ns, 3-4 instructions on a modern Intel processor. On Friday, 6 January 2017 11:21:32 UTC+11, Keith Randall wrote: > > You're not really testing what you think you are testing. > > When you do "_ = load something", the compiler just throws a

[go-nuts] Re: Accessing an slice is too slow than Array

2017-01-05 Thread 'Keith Randall' via golang-nuts
You're not really testing what you think you are testing. When you do "_ = load something", the compiler just throws away the load. You have to use the result somehow to keep the load in the final assembly. What you are actually timing is the speed of the modulo operator (%). For the pointer c

[go-nuts] Re: Accessing an slice is too slow than Array

2017-01-05 Thread Uli Kunitz
A few comments: For such microbenchmarks you need to check the assembler for optimizations. The C code probably removed the complete loop. The Go version and machine architecture is relevant. There were significant changes recently, particular with the introduction of SSA (static single assign