Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-10-10 18:56:24


John Femiani wrote:
>
>> From: Eric Niebler
>>
>> 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.
>
> 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?

There is a nested for loop that executes once per iteration, and it's
only there so that the iteration variable can be a reference. Its
presence incurs an extra test and set of a hidden bool at each
iteration. And on some compilers, there are a couple of extra Boolean
checks before entering the loop.

(Aside: please try to limit the amount of text you quote in your messages.)

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