mirror of
https://github.com/boostorg/chrono.git
synced 2026-01-25 18:12:13 +00:00
Boost.Chrono: Moved to trunk
[SVN r67698]
This commit is contained in:
41
example/test_thread_clock.cpp
Normal file
41
example/test_thread_clock.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// test_thread_clock.cpp ----------------------------------------------------------//
|
||||
|
||||
// Copyright 2009 Vicente J. Botet Escriba
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
|
||||
#include <boost/chrono/thread_clock.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace boost::chrono;
|
||||
|
||||
void test_thread_clock()
|
||||
{
|
||||
#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
|
||||
std::cout << "thread_clock test" << std::endl;
|
||||
thread_clock::duration delay = milliseconds(5);
|
||||
thread_clock::time_point start = thread_clock::now();
|
||||
while (thread_clock::now() - start <= delay)
|
||||
;
|
||||
thread_clock::time_point stop = thread_clock::now();
|
||||
thread_clock::duration elapsed = stop - start;
|
||||
std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
|
||||
start = thread_clock::now();
|
||||
stop = thread_clock::now();
|
||||
std::cout << "thread_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n";
|
||||
#else
|
||||
std::cout << "thread_clock not available\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test_thread_clock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user