post and pre increment impact on performance...
I wondering if there are any advantages of preincrementing in java like in a for like:
for (int i=0; i<aBigNumber; i++)
for (int i=0; i><aBigNumber; ++i)
Would ++i be faster? i++? or same?>
I wondering if there are any advantages of preincrementing in java like in a for like:
for (int i=0; i<aBigNumber; i++)
for (int i=0; i><aBigNumber; ++i)
Would ++i be faster? i++? or same?>
I believe ++i could be a teeny tiny bit faster because you don't have to temporarily store the current alue of i.
Good luck creating realistic code where the difference is noticeable though. You don't pick ++i vs. i++ for performance reasons. You pick the one whose semantics best fits your needs.
Any compiler worth its price will optimize ++i and i++ to the same code when the result is not used.
javac, for example, produces identical bytecode for both.
If you are worried about performance then don't increase i by 1, use 10, and it will be 10 times faster.
> If you are worried about performance then don't
> increase i by 1, use 10, and it will be 10 times
> faster.
I have an routine that increments by "11". It's one faster, isn't it? It's not ten. You see, most blokes, you know, will be incrementing by ten. You're on ten here, all the way up, all the way up, all the way up, you're on ten in your program. Where can you go from there? Where?