Subject: Re: [boost] BOOST_FOREACH slow?
From: Eric Niebler (eric_at_[hidden])
Date: 2008-11-19 01:17:41
Bjørn Roald wrote:
> David Abrahams wrote:
>> Just curious: you didn't compare with std::for_each (e.g. to see the
>> effects of loop unrolling), did you?
> I got:
> g++ -I../../boost_1_37_0 foreach_benchmark.cpp -o foreach_benchmark
(Don't post benchmarks for unoptimized code. People who read benchmarks
do so because they care about performance ... so they compile with
optimizations turned on. Not only are unoptimized benchmarks
uninteresting, they can be downright misleading if people don't realize
what they are looking at.)
> g++ -O3 -I../../boost_1_37_0 foreach_benchmark.cpp -o
> Iterator accumulate took 0.09 seconds.
> Pointer accumulate took 0.09 seconds.
> Iterator for loop took 0.09 seconds.
> Pointer for loop took 0.09 seconds.
> Index for loop took 0.09 seconds.
> Index for_each took 0.09 seconds.
> Pointer for_each took 0.09 seconds.
> BOOST_FOREACH took 0.09 seconds.
> std::for_each took 0.09 seconds.
That looks better. Thanks. So for libstdc++ at least, std::for_each is
no faster. I just checked and it does not do loop unrolling, at least
for 4.3.0, so that's not surprising.
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk