Subject: [ggl] pre-/post-increment op on iterators
From: Mateusz Loskot (mateusz)
Date: 2009-04-25 17:45:54
Barend Gehrels wrote:
> Hi Mateusz,
>> I've noticed that in many (if not most) places where iterators are
>> used, they are advanced using post-increment operator instead of
>> the pre-increment one. Is this intentional?
> Yes and no, more bad (old) habit then intentional. Pre-increment
> seems to perform better so if that is really the case, we should
> change it.
IMHO, it is the case because performance hit from post-increment
may vary even to 50%.
> We've tools to check that :-) Just checked, see below.
>> If not, I'd like to change it to pre-increment as well as propose
>> to add development guideline recommending use of pre-increment
>> operator over the post-increment.
> Yes, please.
> I just compared the difference using convex hull. Did you already
> check the comparison programs?
Not yet, have been busy with flat searching-moving.
> Anyway, our convex hull seems to perform quite good compared with
> others. Using iterator pre-increment instead of post-increment (in
> agn_convex_hull.hpp) makes it another 1.8% faster. So although not
> shocking, it is a measurable improvement (from 0.828 to 0.813
OK, this test case does not show incredible performance
gain, but if we look around on the Web and Usenet comp.lang.c++.*
we can find different results - all if not most of them show that
pre-increment operator performs better. How better, numbers are
different but may be big :-)
Here is one of examples:
> So yes, we should change it. Good you point it out.
OK, I will.
-- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org
Geometry list run by mateusz at loskot.net