]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/timer/test/cpu_timer_info.cpp
1 // boost cpu_timer_info.cpp ----------------------------------------------------------//
3 // Copyright Beman Dawes 2011
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // See http://www.boost.org/libs/timer for documentation.
10 #include <boost/timer/timer.hpp>
11 #include <boost/chrono/chrono.hpp>
12 #include <boost/detail/lightweight_main.hpp>
13 #include <cstdlib> // for atol()
17 using boost::timer::nanosecond_type
;
18 using boost::timer::cpu_times
;
19 using boost::timer::cpu_timer
;
20 using boost::timer::auto_cpu_timer
;
21 using std::cout
; using std::endl
;
23 int cpp_main( int argc
, char * argv
[] )
26 cout
<< "For cpu_times.wall, the underlying clock "
27 << (boost::chrono::high_resolution_clock::is_steady
31 << "Steady clocks are defined by C++11 as clocks for which values "
32 "of time_point never decrease as physical time advances and for "
33 "which values of time_point advance at a steady rate relative to "
34 "real time. That is, the clock may not be adjusted.\n\n";
38 cpu_times current_time
;
42 cout
<< "measure boost::timer::cpu_timer resolution for user time..."
44 for (int i
= 0; i
< 3; ++i
)
47 start_time
= cpu
.elapsed();
48 current_time
.user
= start_time
.user
;
49 while (current_time
.user
== start_time
.user
)
51 current_time
= cpu
.elapsed();
53 cout
<< current_time
.user
- start_time
.user
<< "ns\n";
59 cout
<< "measure boost::timer::cpu_timer resolution for wall-clock time..."
61 for (int i
= 0; i
< 100; ++i
)
64 start_time
.wall
= cpu
.elapsed().wall
;
65 current_time
.wall
= start_time
.wall
;
66 while (current_time
.wall
== start_time
.wall
)
68 current_time
.wall
= cpu
.elapsed().wall
;
70 cout
<< current_time
.wall
- start_time
.wall
<< "ns ";