Performance comparison between ptr_vector and vector<cow_ptr<Shape> >, vector<copy_ptr<Shape> >

This is a continuation on a thread discussion advocating replacing the boost pointer containers with cow_ptr as the default pointer containers. http://code.axter.com/boost_ptr_containers/maintest.cpp http://code.axter.com/shape_test.h http://code.axter.com/cow_ptr.h http://code.axter.com/copy_ptr.h The above code was used to make the comparison, and the following is the result using VC++ 7.1 on XP with a 2G processor. Test performance for interating through a container of pointers via []. vector<copy_ptr<Shape> > 2.20 s boost::ptr_vector<Shape> 3.80 s vector<cow_ptr<Shape> > 7.20 s Test performance for interating through a container of pointers via iterators. vector<copy_ptr<Shape> > 2.36 s boost::ptr_vector<Shape> 4.11 s vector<cow_ptr<Shape> > 6.70 s vector<copy_ptr<Shape> > 2.31 s boost::ptr_vector<Shape> 4.08 s vector<cow_ptr<Shape> > 7.09 s Test performance for initializing and copying container of pointers. vector<copy_ptr<Shape> > 2.39 s boost::ptr_vector<Shape> 2.81 s vector<cow_ptr<Shape> > 0.67 s vector<copy_ptr<Shape> > 2.84 s boost::ptr_vector<Shape> 4.28 s vector<cow_ptr<Shape> > 0.61 s Test performance for populating container of pointers via factory method. vector<copy_ptr<Shape> > 7.00 s boost::ptr_vector<Shape> 1.55 s vector<cow_ptr<Shape> > 3.91 s Press any key to continue . . . I like to see if any one can test this out on other platforms and/or compilers to see if the results differ.

axter wrote:
This is a continuation on a thread discussion advocating replacing the boost pointer containers with cow_ptr as the default pointer containers. http://code.axter.com/boost_ptr_containers/maintest.cpp http://code.axter.com/shape_test.h http://code.axter.com/cow_ptr.h http://code.axter.com/copy_ptr.h The above code was used to make the comparison, and the following is the result using VC++ 7.1 on XP with a 2G processor. Test performance for interating through a container of pointers via [].
I like to see if any one can test this out on other platforms and/or compilers to see if the results differ.
On visual c++ 7.1 I get the following: cl /EHsc /Ox /Og /O2 /DNDEBUG=1 maintest.cpp /I../../boost/boost/ $ ./maintest.exe Test performance for interating through a container of pointers via []. vector<copy_ptr<Shape> > 1.28 s boost::ptr_vector<Shape> 1.27 s vector<cow_ptr<Shape> > 1.41 s
>>>>>>>>>> It appears that you ran the test with BOOST_ASSERT enabled.
Test performance for interating through a container of pointers via iterators. vector<copy_ptr<Shape> > 1.28 s boost::ptr_vector<Shape> 1.22 s vector<cow_ptr<Shape> > 1.34 s
>>>>>>>>>>>
I precalculated the end() iterator, as one would normally do. This seems to be slightly slower in ptr_vector, which makes sense given the extra wrapper layer. Test performance for initializing and copying container of pointers. vector<copy_ptr<Shape> > 0.42 s boost::ptr_vector<Shape> 0.42 s vector<cow_ptr<Shape> > 0.09 s
>>>>>>>>>>>>
cow_ptr seems to win here. I can't figure out why cow_ptr is so much faster. ptr_vector uses cloning, of course, whereas cow_ptr does something else. Test performance for populating container of pointers via factory method. vector<copy_ptr<Shape> > 0.30 s boost::ptr_vector<Shape> 0.08 s vector<cow_ptr<Shape> > 0.11 s Tryk på en vilkårlig tast for at fortsætte . . . -Thorsten

Thorsten Ottosen wrote:
axter wrote:
This is a continuation on a thread discussion advocating replacing the boost pointer containers with cow_ptr as the default pointer containers.
Test performance for initializing and copying container of pointers.
vector<copy_ptr<Shape> > 0.42 s
boost::ptr_vector<Shape> 0.42 s
vector<cow_ptr<Shape> > 0.09 s
>>>>>>>>>>>>>
cow_ptr seems to win here. I can't figure out why cow_ptr is so much faster. ptr_vector uses cloning, of course, whereas cow_ptr does something else.
I further tried to add the proper return type to the functions, such that ptr_vector<T> returns by auto_ptr< ptr_vector<T> > and vector<T> as vector<T>. On top of this, I save the return-value and called size() on it. This gave: Test performance for initializing and copying container of pointers. vector<copy_ptr<Shape> > 1.42 s boost::ptr_vector<Shape> 0.81 s vector<cow_ptr<Shape> > 0.13 s But this test is a bit unfair: we create copies of the vector, but we never mutate that copy. A fair test would mutate all the elements. -Thorsten
participants (2)
-
axter
-
Thorsten Ottosen