|
-
September 9th, 2007, 10:01 AM
#1
Basic Stuff
Hello,
i am doing my undergraduation....one of my friends said pre increment/decrement is more efficient in implementaion than post increment/decrement...but when i asked him the explanation he said he just heard it(??????!!!!!!!!)...but i dont think efficiency is related to the order of execution if its just a single line like:
++x;
(or)
x++;
could any one pls say whether it is a valid argument or its just a gag...sorry if its too elementary....
thank you
-
September 9th, 2007, 04:59 PM
#2
Re: Basic Stuff
 Originally Posted by aad1986
but i dont think efficiency is related to the order of execution if its just a single line like:
++x;
(or)
x++;
For basic types, there's no difference between these two statements.
For compound iterators of complex objects such as std: eque, pre-increment might sometimes be slightly faster than post-increment due to the fact that it saves a temporary that the compiler doesn't optimize out.
For a very good compiler, there should be no difference.
Anyway, for basic types, even with a BAD compiler, there's no speed difference.
could any one pls say whether it is a valid argument or its just a gag...sorry if its too elementary....
It's wiser to think that it's a gag. Making difference between those two constructs is a path to inefficient coding: When a programmer is concerned with pseudo-micro-optimizations, 50% of the time he decreases performances, and in every case, he never gives any big performance boost to his programs.
In the same set of gags, there are recurring questions about what iteration statement (while, for and do-while) has the best performance. All of them perform identically at negligible random differences.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|