| 
									
										
										
										
											2002-02-16 16:09:08 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  shared_ptr_timing_test.cpp - use to evaluate the impact of thread safety
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2004-07-26 00:32:12 +00:00
										 |  |  | // Distributed under the Boost Software License, Version 1.0. (See
 | 
					
						
							|  |  |  | // accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | // http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2002-02-16 16:09:08 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-15 18:06:17 +00:00
										 |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <ctime>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int const n = 8 * 1024 * 1024; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-02-08 16:05:46 +00:00
										 |  |  |     using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-15 18:06:17 +00:00
										 |  |  |     std::vector< boost::shared_ptr<int> > v; | 
					
						
							|  |  |  |     boost::shared_ptr<int> pi(new int); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-08 16:05:46 +00:00
										 |  |  |     clock_t t = clock(); | 
					
						
							| 
									
										
										
										
											2002-02-15 18:06:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for(int i = 0; i < n; ++i) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         v.push_back(pi); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-08 16:05:46 +00:00
										 |  |  |     t = clock() - t; | 
					
						
							| 
									
										
										
										
											2002-02-15 18:06:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     std::cout << static_cast<double>(t) / CLOCKS_PER_SEC << '\n'; | 
					
						
							| 
									
										
										
										
											2003-02-08 16:05:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2002-02-15 18:06:17 +00:00
										 |  |  | } |