shared_ptr_timing_test.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <boost/config.hpp>
  2. #if defined(BOOST_MSVC)
  3. #pragma warning(disable: 4786) // identifier truncated in debug info
  4. #pragma warning(disable: 4710) // function not inlined
  5. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  6. #pragma warning(disable: 4514) // unreferenced inline removed
  7. #endif
  8. //
  9. // shared_ptr_timing_test.cpp - use to evaluate the impact of thread safety
  10. //
  11. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  12. //
  13. // Distributed under the Boost Software License, Version 1.0. (See
  14. // accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. //
  17. #include <boost/shared_ptr.hpp>
  18. #include <iostream>
  19. #include <vector>
  20. #include <ctime>
  21. int const n = 8 * 1024 * 1024;
  22. int main()
  23. {
  24. using namespace std;
  25. std::vector< boost::shared_ptr<int> > v;
  26. boost::shared_ptr<int> pi(new int);
  27. clock_t t = clock();
  28. for(int i = 0; i < n; ++i)
  29. {
  30. v.push_back(pi);
  31. }
  32. t = clock() - t;
  33. std::cout << static_cast<double>(t) / CLOCKS_PER_SEC << '\n';
  34. return 0;
  35. }