Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-10-10 18:03:51


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 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