1 #include <boost/config.hpp>
3 #if defined(BOOST_MSVC)
4 #pragma warning(disable: 4786) // identifier truncated in debug info
5 #pragma warning(disable: 4710) // function not inlined
6 #pragma warning(disable: 4711) // function selected for automatic inline expansion
7 #pragma warning(disable: 4514) // unreferenced inline removed
11 // weak_ptr_timing_test.cpp
13 // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
14 // Copyright 2005 Peter Dimov
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
21 #include <boost/shared_ptr.hpp>
22 #include <boost/weak_ptr.hpp>
34 void test( std::vector< boost::shared_ptr<int> > & v )
36 using namespace std; // printf, rand
38 std::vector< boost::weak_ptr<int> > w( v.begin(), v.end() );
42 for( int i = 0; i < n; ++i )
44 // randomly kill a pointer
46 v[ rand() % k ].reset();
48 for( int j = 0; j < k; ++j )
50 if( boost::shared_ptr<int> px = w[ j ].lock() )
57 w[ j ] = v[ rand() % k ];
62 printf( "\n%d locks, %d rebinds.", s, r );
67 using namespace std; // printf, clock_t, clock
69 std::vector< boost::shared_ptr<int> > v( k );
71 for( int i = 0; i < k; ++i )
73 v[ i ].reset( new int( 0 ) );
82 printf( "\n\n%.3f seconds.\n", static_cast<double>( t ) / CLOCKS_PER_SEC );