
Peter Bartlett wrote:
Quoting Hansi <hansipet@web.de>:
regarding to the benchmark link posted from Michael Marcin BOOST_FOREACH is 3 times slower then other equivalents...it is a lot...
Best regards Hansjörg
And that should make you sceptical of the results! Once you strip away the TMP and macros, FOREACH is not much different from a for lopp. There is an additional boolean [or so?] that looks ripe for optimization.
Yes, one extra boolean test/set per iteration. That's all you should pay for using BOOST_FOREACH when optimizations are turned on. I can't get rid of it without also getting rid of the ability to iterate over a sequence by reference.
Checking that premise: I just re-ran Michael's test with VC9 on full optimization and _SECURE_SCL=0. My results are:
Iterator accumulate took 0.235 seconds. Pointer accumulate took 0.265 seconds. Iterator for loop took 0.234 seconds. Pointer for loop took 0.25 seconds. Index for loop took 0.281 seconds. Index for_each took 0.235 seconds. Pointer for_each took 0.25 seconds. BOOST_FOREACH took 0.25 seconds. MSVC for each took 0.234 seconds. Press any key to continue . . .
Thanks Peter! -- Eric Niebler BoostPro Computing http://www.boostpro.com