• Post Reply Bookmark Topic Watch Topic
  • New Topic

which is more efficient/faster: Pre increment or post increment operator?  RSS feed

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which is more efficient/faster: Pre increment or post increment operator or does not matter?
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is is a difference, it is in all likelihood too miniscule to be measured; I wouldn't worry about it. There can be a semantic difference, depending on how they're used, which you should not disregard, though.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Liek wrote:which is more efficient/faster: Pre increment or post increment operator or does not matter?

It doesn't matter. As Ulf says, they don't do the same thing, but the chances are that (at least at this stage) you shouldn't be writing code where the distinction matters - ie, always increment in a separate statement.

For a few other things that you probably don't need to worry about, you can also check out the DontSweatIt page but, as a general rule, speed should be the LAST thing you think about. The only question you normally need to know is: is it fast enough?

One of my favourite quotes on the subject (used to be my signature):
"More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity." — W.A. Wulf

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!