Dave Zarzycki showed how the efficiency of shared_ptr could be significantly

increased.  The following program is running 49% faster:

#include <iostream>
#include <memory>
#include <chrono>
#include <vector>
#include "chrono_io"

int main()
{
    typedef std::chrono::high_resolution_clock Clock;
    Clock::time_point t0 = Clock::now();
    {
        std::shared_ptr<int> p(new int (1));
        std::vector<std::shared_ptr<int> > v(1000000, p);
        v.insert(v.begin(), p);
        v.insert(v.begin(), p);
        v.insert(v.begin(), p);
        v.insert(v.begin(), p);
    }
    Clock::time_point t1 = Clock::now();
    std::cout << (t1-t0) << '\n';
}


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@119388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2010-11-16 21:33:17 +00:00
parent 726a76fb47
commit 28dbbe0596
2 changed files with 8 additions and 5 deletions

View File

@@ -2535,7 +2535,7 @@ public:
: __shared_owners_(__refs) {}
void __add_shared();
void __release_shared();
bool __release_shared();
_LIBCPP_INLINE_VISIBILITY
long use_count() const {return __shared_owners_ + 1;}
};