
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?
<snip>
I got: g++ -I../../boost_1_37_0 foreach_benchmark.cpp -o foreach_benchmark <snip>
(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 foreach_benchmark 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