By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

Whats faster? i1++ or ++i1

P: n/a
I'm wondering if I will get faster code in any case if I use i1++.

Do you have any experiences?

Apr 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
thebrath wrote:
I'm wondering if I will get faster code in any case if I use i1++.


If il++ calls an overloaded operator++(int), and if that is slower than
operaor++() (the ++il form), then it will be slower.

As a style thing, get in the habit of always typing ++il because it's
"weaker" than il++. It has less features.

That rule is just to make ++il easier to understand. The built-in version of
il++ can easily be optimized as fast as ++il.

Google for "premature optimization" now.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 14 '06 #2

P: n/a
Phlip wrote:
thebrath wrote:
I'm wondering if I will get faster code in any case if I use i1++.


If il++ calls an overloaded operator++(int), and if that is slower than
operaor++() (the ++il form), then it will be slower.

As a style thing, get in the habit of always typing ++il because it's
"weaker" than il++. It has less features.

That rule is just to make ++il easier to understand. The built-in version of
il++ can easily be optimized as fast as ++il.

Google for "premature optimization" now.


Your question is in the FAQ. Please see:
http://www.parashift.com/c++-faq-lite/

Apr 14 '06 #3

P: n/a
Alan Johnson wrote:
Phlip wrote:
thebrath wrote:
I'm wondering if I will get faster code in any case if I use i1++.


If il++ calls an overloaded operator++(int), and if that is slower than
operaor++() (the ++il form), then it will be slower.

As a style thing, get in the habit of always typing ++il because it's
"weaker" than il++. It has less features.

That rule is just to make ++il easier to understand. The built-in
version of
il++ can easily be optimized as fast as ++il.

Google for "premature optimization" now.


Your question is in the FAQ. Please see:
http://www.parashift.com/c++-faq-lite/


Sorry. I meant to reply to the original poster, of course.

Alan
Apr 14 '06 #4

P: n/a

thebrath wrote:
I'm wondering if I will get faster code in any case if I use i1++.

Do you have any experiences?


Always use the most generic method with the least amount of
requirements and does the least amount of work as possible. i++
requires the original value of i to be returned. In the case of
iterators this means returning a copy...it does more work than is
necessary for the task unless you really need the previous value. ++i
is more generic, has less requirements, and does less work...use it
when you can, which is most of the time in my experience.

The reason you do this is so that if you change what i is, so long as
it has the correct interface, it will work and be as fast as it can be.
Don't optimize prematurely, but don't pesimize prematurely either.

Apr 14 '06 #5

P: n/a
Alan Johnson wrote:
Your question is in the FAQ.¬*¬*Please¬*see:
http://www.parashift.com/c++-faq-lite/


Sorry.¬*¬*I¬*meant¬*to¬*reply¬*to¬*the¬*original¬* poster,¬*of¬*course.


Not at all; I should have cited the FAQ too!

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.