post/pre increment operator speed
Hi, i was wonder if the expression:
++j
is faster than
j++
Let's think to a for cycle:
for(j=0; j<array.length; ++j) {
foo.staff();
}
at the last cycle, after the foo.staff() execution, what will happen will be that j will be incremented before to be considered for the condition. It should be different from the other expression, as in the case of j++, first j would be considered and then incremented.
WFYI(Waiting for your impressions).
Re: Difference ++j and J++
I don't know how exactly you mean by faster....
As far as efficiency is concerned, both are equal. Both has the efficiency level constant in terms of Anaylsis.
Re: post/pre increment operator speed
Please don't hijack someone else's thread, I've moved your question into it's own thread.
The two pieces of code run the loop different number of times so it's not a fair comparison.
As far as ++j or j++ itself is concerned, the Java compiler is smart enough to make sure these statements will both execute in more or less the same time.
The same can't be said for languages which allow operator overloading (e.g. C++), and it depends on the implementation.
Re: post/pre increment operator speed
What happened when you wrote a small test program that profiled each operation for you? Say, do each a million times and see how long it takes?