Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
They say that ++i
is faster but I don't understand why.Can anybody show me assembler codes of these operators?
Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
They say that ++i
is faster but I don't understand why.Can anybody show me assembler codes of these operators?
++i
is definitiely as fast as i++
but it may be faster.
The reason is the implementation.
In order to implement i++
the implementation needs to generate a temporary copy of i
unlike the implementation for ++i
.
But smart compilers can optimize the genration of this temporary, they certainly do for POD types.
It depends on the compiler and the situation if it generates faster code for this expression.