Re: A few questions on C++
On Sep 19, 3:53 pm, Vladislav.Lazare...@gmail.com wrote:
On Sep 19, 4:44 pm, Neelesh Bodas <neelesh.bo...@gmail.com> wrote:
On Sep 19, 6:16 pm, "Phlip" <phlip...@yahoo.com> wrote:
4) Should one favor '++iterator' over 'iterator++'? I did some
performance tests myself and did not see a big gap between their
execution times ( by using containers with size 10000000 which con=
tain
objects )
Preincrements are generally faster than postincrements since
postincrements need to make a copy before doing an increment. No su=
ch
copy-construction is necessary for pre-increment.
Can't most compilers optimize all that away for simple values?
As I understand it, For PODs (if that is what you mean by 'simple
values'), the pre- or post- increment doesnot make any difference from
the POV of efficiency. But for complex data types, I don't see how
would a compiler optimize away the copy construction.
E pore. All the ones I use do. At least, my measurements show
no difference in performance.
Post-increment always performs copying. So there is always difference.
Sure, you won't see it for integers etc.
Always use pre-increment except situation when you really need pre-
increment.
That's the sort of pronouncement an inexperienced amateur might
make. A professional will consider all of the variables
involved. On a green fields project, with no existing code, you
choose one; why not pre-increment? If existing code is present,
you conform to its standards, unless there is a strong advantage
in not doing so. In this case, there is none.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34