Re: Postfix is slower than postfix: how likely?
Tom?s wrote:
Seungbeom Kim posted:
I might not have made myself clear, but I'm afraid that's
not what I asked; I know why prefix is preferred and I've
been advocating it to other people for quite a long time.
But people (especially those in the habit of writing postfix
for no particular reason and reluctant to change) would ask
me if there really was any difference and how likely it
would be (so that they could be convinced to convert, or
they would just stay where they were and continue to write
postfix). That's why and what I asked. Hopefully I made
myself clearer this time.
Very simple. Get a really big, complicated class whose
copy-constructor takes a long time to run.
Now you're being silly. Such classes can't be used as
iterators. That's all there is to it. The STL copies iterators
right and left -- any iterator which is expensive to copy will
give unacceptable performance with the STL.
Then time a loop:
for( ExpensiveClass i; i < 999; ++i) ;
Versus:
for( ExpensiveClass i; i < 999; i++) ;
If they really need that much convincing, they won't be Grade
A programmers.
If they pay any attention to such artificial measures, they
aren't very professional. The question that Seungbeom asked was
very concrete -- what is the probability of it actually making a
difference in a real program? Which is the only question which
would really concern a professional programmer.
(Also turn off all compiler optimizations for good measure).
Let's see -- we're worried about performance, so we turn off all
compiler optimizations. I've never worked in an organization
that worked like that. (We generally deliver without any
optimizations, because we don't need the speed, and compilers
are generally more reliable with optimization turned off. But
when performance is an issue, compiler optimizations are
generally more reliable than manual optimizations.)
--
James Kanze GABI Software
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! ]