Re:C++ for Games: Performance, Allocations and Data Locality
by daemin on Monday May 30, 2016 @05:46AM
(#11800503)
The example you gave is actually different code and are not directly comparable. With i = 0; x = array[i++] will access the first element, x = array[++i] will access the second element. So of course in the second case the array load will wait until it gets the incremented value.
Edit: The same code with a preincrement notation would be x = array[i]; ++i;
Re:C++ for Games: Performance, Allocations and Data Locality
by ifdefdebug on Monday May 30, 2016 @07:22AM
(#11800755)
The cited statement accounts for this:
> Obviously, the initial value of i must be adjusted
> if you change pre-increment to post-increment.
I often still sometimes write "++it" out of habit, but usually will just go with whichever variant I feel conveys my intent better and leave the optimisation of this to the compiler.
EDIT:
Its also not always true that "++it" is faster than "it++", as this quote from Agner Fog's C++ optimisation guide notes: