Boost logo

Boost :

Subject: Re: [boost] [Block Pointer] Up to 600% faster than Shared Pointer
From: Phil Bouchard (philippeb8_at_[hidden])
Date: 2016-03-12 13:40:49


On 03/12/2016 01:06 PM, Glen Fernandes wrote:
> On Sat, Mar 12, 2016 at 12:37 PM, Phil Bouchard wrote:
>> On 03/11/2016 11:12 PM, Glen Fernandes wrote:
>>>
>>> Hi Phil,
>>>
>>> What exactly are you measuring here? The time taken to construct an
>>> std::auto_ptr<T>/std::shared_ptr<T>/block_ptr<T> inclusive of the time
>>> taken for ::operator new(std::size_t) and inclusive of the
>>> value-initialization T::T() ?
>>
>>
>> Yes but it also calls ::operator delete(void *) and T::~T().
>>
>> If I don't use fastblock<>() then it's a simple 150% speedup compared to
>> shared_ptr<>:
>>
>> new:
>> auto_ptr: 22279670 ns
>> shared_ptr: 47428316 ns
>> block_ptr: 31287440 ns
>>
>>
>> My point with fastblock<>() is that it can be use very easily because it is
>> already integrated.
>>
>
> Since everyone prefers make_shared<T>(args...) when possible instead
> of shared_ptr<T>(new T(args...)), I'm not sure that the benchmark of
> the latter is very useful.
>
> Rather, given that the preferred use of shared_ptr<T> is with
> make_shared() or allocate_shared(), I think you should at least
> include that benchmark in this list.
>
> Otherwise you're essentially measuring the cost of 2 ::operator
> new(std::size_T) calls (that most people wouldn't write) instead of
> the 1 ::operator new(std::size_t) call (that most people would write).

Good point. If I compare make_shared<>() with new block<>() then the
speeds are almost the same:

make:
auto_ptr: 25614443 ns
shared_ptr: 26603216 ns <-

new:
auto_ptr: 23529804 ns
shared_ptr: 49876800 ns
block_ptr: 29975876 ns <-

If I compare make_shared<>() with new fastblock<>() I have a 300% speedup:

make:
auto_ptr: 25672479 ns
shared_ptr: 27077638 ns <-

new:
auto_ptr: 22647604 ns
shared_ptr: 53317702 ns
block_ptr: 8911600 ns <-

> You might as well start replacing auto_ptr with unique_ptr, just to
> honor the fact that the former is deprecated. :-)

I tried to quickly but for some reason auto_ptr<> is still the one
dangling around in my GCC API.

Regards,
-Phil


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk