Link Details

Link 117228 thumbnail
User 111696 avatar

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.
  • 7
  • 2
  • 1273
  • 319

Comments

Add your comment
User 285418 avatar

Motion Control replied ago:

1 votes Vote down Vote up Reply

> One guy asked a question on a Java Forum: which operation is faster - post-increment or pre-increment.

Must have been a C++ developer ...

User 276353 avatar

Umberto replied ago:

0 votes Vote down Vote up Reply

it sounds more a .Net developer than a C++ in my view:)

User 285418 avatar

Motion Control replied ago:

0 votes Vote down Vote up Reply

.Net languages have operator overloading?? I must have missed something ...

User 276353 avatar

Umberto replied ago:

0 votes Vote down Vote up Reply

just wish it had..

User 239201 avatar

amphi replied ago:

0 votes Vote down Vote up Reply

++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. :)

User 261293 avatar

joecoder replied ago:

0 votes Vote down Vote up Reply

Yeah, several flaws in both the benchmarking and the general reasoning surrounding it. I'm surprised this article was voted up like it way.

User 438758 avatar

reenu1 replied ago:

0 votes Vote down Vote up Reply

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

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (2)