Boost logo

Boost Users :

From: John Femiani (JOHN.FEMIANI_at_[hidden])
Date: 2007-10-10 18:23:23


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Eric Niebler
> Sent: Wednesday, October 10, 2007 3:04 PM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Container iteration macro that is
equivalent
> tohandcoded iteration?
>
> Michael Marcin wrote:
> > Erik wrote:
> >>
> >> Or is it possible to configure BOOST_FOREACH to be as efficient as
my
> macro?
> >
> > I don't know but that is a good question.
> >
> > I considered using BOOST_FOREACH until I checked its generated
output...
> > which was worse than std::for_each with a boost::bind which was
worse
> > than std::for_each with a hand coded functor which was worse than a
hand
> > coded for loop like yours above.
>
>
> I won't deny that the abstraction penalty of BOOST_FOREACH is not
zero,
> but have either of you actually measured the overhead? I have, and I
> found BOOST_FOREACH to be about 5% slower than the equivalent
hand-coded
> loop when compiler optimizations are turned on. It's really very
small,
> and that 5% buys you a lot of expressivity. YMMV.
>
> --
> Eric Niebler
> Boost Consulting
> www.boost-consulting.com
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

Where does the 5% come from? Which part of BOOST_FOREACH (which is way
to advanced for me to understand) is the part that causes the most
trouble with compilers? Is it the extra if statement trick that seems
to be used to initialize the variable?

-- John


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net