From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-11-15 09:13:11
On Fri, Nov 12, 2004 at 04:15:31PM -0700, Richard Newman wrote:
> David Abrahams wrote:
> > Richard Newman <richard_at_[hidden]> writes:
> >> So, the new current thinking is that std::accumulate is Better than
> >> simple while-loops that walk through elements which is still Bad.
> >> However, boost::bind under std::accumulate is Worse. At this point, the
> >> best advice is that one should use std::accumulate whenever simple
> >> accumulations are needed. However, once one has to start involving
> >> boost::bind on 1+-ary functions or anything else that requires new
> >> run-time function redirection, then retreating back to while-loop is a
> >> better performance solution.
> > This all depends on your compiler's optimization capabilities. If the
> > compiler can't detect that the value of the function pointer is known
> > at compile-time, then yes, bind will cost you. Similarly, if it can't
> > do the small object optimization, transform_iterator may cost you.
> > This is the unfortunate problem of abstraction penalty in C++. If you
> > want optimal performance, you can either write low-level code, improve
> > your compiler, or switch to a language that supports guaranteed
> > optimization (see http://osl.iu.edu/~tveldhui/).
> > Cheers,
> Thank you, Dave, for replying. I will check out the link.
> Do you have specific advice/experience for Linux's g++ that might improve or
> explain what we're seeing here?
It's possible that hand-rolling functors to pass to std::accumulate will
beat the boost::bind / boost::transform_iterator versions, and maybe still
beat the explicit while loop in some cases.
Then again, it's possible it won't.
-- "Whenever you find that you are on the side of the majority, it is time to reform." - Mark Twain
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk