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