
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