• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which is more efficient/faster: Pre increment or post increment operator or does not matter?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic