test_thread_clock.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // test_thread_clock.cpp ----------------------------------------------------------//
  2. // Copyright 2009 Vicente J. Botet Escriba
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. #include <boost/chrono/thread_clock.hpp>
  6. #include <boost/type_traits.hpp>
  7. #include <iostream>
  8. void test_thread_clock()
  9. {
  10. #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
  11. using namespace boost::chrono;
  12. std::cout << "thread_clock test" << std::endl;
  13. thread_clock::duration delay = milliseconds(5);
  14. thread_clock::time_point start = thread_clock::now();
  15. while (thread_clock::now() - start <= delay)
  16. ;
  17. thread_clock::time_point stop = thread_clock::now();
  18. thread_clock::duration elapsed = stop - start;
  19. std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
  20. start = thread_clock::now();
  21. stop = thread_clock::now();
  22. std::cout << "thread_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
  23. #else
  24. std::cout << "thread_clock not available\n";
  25. #endif
  26. }
  27. int main()
  28. {
  29. test_thread_clock();
  30. return 0;
  31. }