Re: ques and and level order traversal
Carl Barron wrote:
In article <el7b04$e4t$1@nemesis.news.tpi.pl>, Dariusz Bismor
<Dariusz.Bismor@polsl.pl> wrote:
That is surely a newbie question, but why should one use only prefix
increment. I thought one should choose one of them (if possible), the one
that suits the best, and use it consequently, with all the consequences.
Because unless the type is simple prefix increment is USSUALLY
cheaper to impliment than post fix increment.
Do you have any measurements to back up this statement? Any
real code where it makes a measurable difference?
I once ran benchmarks of the g++ implementation, for all of the
standard iterators, and was unable to find any measurable
difference.
for(C::iterator it = c.begin();it != c.end(); ++it) does not require
any copies of it but
for(C::iterator it = c.begin();it!= c.end();it++) does until and if an
optimizer removes the copy...
That is the rationale , its ussually cheaper....
Actually, the claimed rationale is that prefix will never be
more expensive, and that it might be cheaper. Sometimes. My
own measurements suggest that this sometimes is in fact pretty
rare, if it exists at all. My own analysis is that the only
possible difference would be an extra copy, and that if copying
an iterator is expensive enough for this to make a difference,
you're going to have performance problems elsewhere, because the
STL copies iterators like crazy, passing them by value, etc.
My own opinion is that beginning programmers, and even those
with more experience, have more important things to worry about.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]