]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/ptr_container/test/pointainer_speed.cpp
716a5a0c2792feb7e0c7800043e9afeb0bb1612d
2 // Boost.Pointer Container
4 // Copyright Thorsten Ottosen 2003-2005. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/ptr_container/
12 #include "test_data.hpp"
13 #include <boost/ptr_container/ptr_vector.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <boost/progress.hpp>
18 using namespace boost
;
22 typedef shared_ptr
<Base
> PolyPtr
;
26 void operator()( const PolyPtr
& a
)
32 bool operator()( const PolyPtr
& l
, const PolyPtr
& r
) const
37 bool operator()( const Base
* l
, const Base
* r
) const
45 bool operator()( const PolyPtr
& l
, const PolyPtr
& r
) const
50 bool operator()( const Base
* l
, const Base
* r
) const
58 bool operator()( const PolyPtr
& l
, const PolyPtr
& r
) const
60 return l
->data_less_than(*r
);
63 bool operator()( const Base
* l
, const Base
* r
) const
65 return l
->data_less_than(*r
);
69 struct data_less_than2
71 bool operator()( const PolyPtr
& l
, const PolyPtr
& r
) const
73 return l
->data_less_than2(*r
);
76 bool operator()( const Base
* l
, const Base
* r
) const
78 return l
->data_less_than2(*r
);
85 enum { size
= 50000 };
87 ptr_vector
<Base
> pvec
;
91 for( int i
= 0; i
< size
; ++i
)
92 svec
.push_back( PolyPtr( new Derived
) );
93 cout
<< "\n shared_ptr call new: ";
98 for( int i
= 0; i
< size
; ++i
)
99 pvec
.push_back( new Derived
);
100 cout
<< "\n smart container call new: ";
104 progress_timer timer
;
105 for_each( svec
.begin(), svec
.end(), PolyPtrOps() );
106 cout
<< "\n shared_ptr call foo(): ";
110 progress_timer timer
;
111 for_each( pvec
.begin(), pvec
.end(), mem_fun_ref( &Base::foo
) );
112 cout
<< "\n smart container call foo(): ";
116 progress_timer timer
;
117 sort( svec
.begin(), svec
.end(), less_than() );
118 cout
<< "\n shared_ptr call sort(): ";
122 progress_timer timer
;
123 sort( pvec
.ptr_begin(), pvec
.ptr_end(), less_than() );
124 cout
<< "\n smart container call sort(): ";
128 progress_timer timer
;
129 sort( svec
.begin(), svec
.end(), greater_than() );
130 cout
<< "\n shared_ptr call sort() #2: ";
134 progress_timer timer
;
135 sort( pvec
.ptr_begin(), pvec
.ptr_end(), greater_than() );
136 cout
<< "\n smart container call sort() #2: ";
140 progress_timer timer
;
141 sort( svec
.begin(), svec
.end(), data_less_than() );
142 cout
<< "\n shared_ptr call sort() #3: ";
146 progress_timer timer
;
147 sort( pvec
.ptr_begin(), pvec
.ptr_end(), data_less_than() );
148 cout
<< "\n smart container call sort() #3: ";
152 progress_timer timer
;
153 sort( svec
.begin(), svec
.end(), data_less_than2() );
154 cout
<< "\n shared_ptr call sort() #4: ";
158 progress_timer timer
;
159 sort( pvec
.ptr_begin(), pvec
.ptr_end(), data_less_than2() );
160 cout
<< "\n smart container call sort() #4: ";
164 for( ptr_vector
<Base
>::ptr_iterator i
= pvec
.ptr_begin(); i
!= pvec
.ptr_end(); ++ i
)
165 copy1
.push_back( *i
);
167 sort( pvec
.ptr_begin(), pvec
.ptr_end() );
171 for( ptr_vector
<Base
>::ptr_iterator i
= pvec
.ptr_begin(); i
!= pvec
.ptr_end(); ++ i
)
172 copy2
.push_back( *i
);
175 for( unsigned int i
= 0; i
< copy1
.size(); ++i
)
178 for( int j
= 0; j
< copy1
.size(); ++ j
)
179 if( copy1
[i
] == copy2
[j
] )
183 cout
<< copy1
[i
] << endl
;
186 BOOST_REQUIRE( pvec
.size() == size
);
191 #include <boost/test/unit_test.hpp>
192 using boost::unit_test::test_suite
;
194 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
196 test_suite
* test
= BOOST_TEST_SUITE( "Pointer Container Test Suite" );
198 test
->add( BOOST_TEST_CASE( &test_speed
) );