Is there a performance difference between i++
and ++i
if the resulting value is not used?
Here's an additional observation if you're worried about micro optimisation. Decrementing loops can 'possibly' be more efficient than incrementing loops (depending on instruction set architecture e.g. ARM), given:
for (i = 0; i < 100; i++)
On each loop you you will have one instruction each for:
1
to i
. i
is less than a 100
.i
is less than a 100
.Whereas a decrementing loop:
for (i = 100; i != 0; i--)
The loop will have an instruction for each of:
i
, setting the CPU register status flag.Z==0
).Of course this works only when decrementing to zero!
Remembered from the ARM System Developer's Guide.