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). You might as well start replacing auto_ptr with unique_ptr, just to honor the fact that the former is deprecated. :-) Glen