|
Boost : |
Subject: Re: [boost] [range] Performance benchmarks?
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2012-02-02 05:33:31
Den 01-02-2012 18:02, Mathias Gaunard skrev:
> On 02/01/2012 04:39 PM, Beman Dawes wrote:
>> A question came up in a long bikeshed discussion on a C++ committee
>> mailing list as to the performance of range based interface versus a
>> begin/end iterator interface (I.E. traditional STL interface) to the
>> same algorithms.
>
> It's exactly the same performance, because a range is just a pair of
> begin/end iterators and all the code is implemented using the iterators.
Well, sometimes the high-leve range adaptors can make better decisions.
For exmple, assuming the adaptors don't turn the iterators into
bidirectional iterators, boost::push_back( out_range, ... ) will
only grow the output vector once. Of course, the old version can call
reserve(), if people remember that.
OTOH, range adaptors sometimes inhibit (manual) loop-unrolling. For
example, copy_if( ... ) can unroll the inner loop for random access
iterator wheres copy( ... | filtered(...) ...) cannot.
I suspect that the difference is minor because the iterator comparison
will be dwarfed by the cost of calling the predicate and copying the value.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk