By bloid
via blogs.sun.com
Published: Sep 22 2008 / 12:00
One guy asked a question on a Java Forum: which operation is faster - post-increment or pre-increment. I really don't feel these things make a big difference in code performance. I have written a small code to check what nanosecond API of Java is telling about it. And again I reached to a wrong benchmarking.
Comments
Motion Control replied ago:
> One guy asked a question on a Java Forum: which operation is faster - post-increment or pre-increment.
Must have been a C++ developer ...
Umberto replied ago:
it sounds more a .Net developer than a C++ in my view:)
Motion Control replied ago:
.Net languages have operator overloading?? I must have missed something ...
Umberto replied ago:
just wish it had..
amphi replied ago:
++x is faster than x++, because it does a little less. If it's side-effect-free (i.e. a single statement) it can and will be compiled to the same code. If the code relies on those side-effects, it's probably a bit ugly. (E.g. int[]a={1,2,3}; for(int i=a.length;i-->0;)System.out.println(a[i]);)
By the way that benchmark is totally flawed. :)
joecoder replied ago:
Yeah, several flaws in both the benchmarking and the general reasoning surrounding it. I'm surprised this article was voted up like it way.
reenu1 replied ago:
in normal case if we use ++x and x++,both work same.But in classes,that overload the ++ operator,it's faster to use the ++x rather than x++.
http://www.teethwhiteninginstructions.com
Voters For This Link (7)
Voters Against This Link (2)