Boost logo

Boost :

From: David Maisonave (dmaisonave_at_[hidden])
Date: 2006-01-10 11:08:39

I'm doing performance test comparing different containers of smart
pointers to the boost pointer containers.


>From my test, it does seem that boost::ptr_vector does seem to do a much
better job of populating the container than does a std::vector container
of boost::shared_ptr, cow_ptr, and copy_ptr.


I was really surprise to find out that ptr_vector was 2 to 3 times
faster than vector<cow_ptr<T> >, but I was even more surprise to find
that it was also 2 to 3 times faster than vector<shared_ptr<T> >.

In fact, even the copy_ptr was twice as fast as the boost::shared_ptr
and cow_ptr in populating the container.


It seems reference counting has a much bigger impact on performance than
I had anticipated.

Can someone else run this test on a different platform, to see if they
get similar results:

I used the following code:


My test was done on Windows XP Pro and 2003 Server.

I used VC++ 7.1


Here's an example of one of the results I'm getting:


vector<copy_ptr<Shape> > 1.30 s

boost::ptr_vector<Shape> 0.88 s

vector<cow_ptr<Shape> > 3.31 s

vector<boost::shared_ptr<Shape> > 2.97 s

vector<copy_ptr<Shape> > 1.19 s

boost::ptr_vector<Shape> 0.67 s

vector<cow_ptr<Shape> > 3.25 s

vector<boost::shared_ptr<Shape> > 2.92 s



I believe the performance hit is coming from having to call new on the
constructor. I'm wondering if there's a more efficient way to do
reference counting that can avoid calling new.

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