Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-11-12 17:48:12

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


Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at