1 // example/stopwatch_example.cpp ---------------------------------------------------//
2 // Copyright Beman Dawes 2006, 2008
3 // Copyright 2009-2011 Vicente J. Botet Escriba
4 // Copyright (c) Microsoft Corporation 2014
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
10 #include <boost/chrono/stopwatches/strict_stopwatch.hpp>
11 #include <boost/chrono/chrono_io.hpp>
12 #include <boost/chrono/process_cpu_clocks.hpp>
15 using namespace boost::chrono
;
17 #ifdef BOOST_CHRONO_HAS_PROCESS_CLOCKS
18 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
19 typedef process_cpu_clock clock_type
;
21 // Windows store doesn't support process_cpu_clock, default to high_resolution_clock.
22 typedef high_resolution_clock clock_type
;
25 typedef high_resolution_clock clock_type
;
30 template<class Rep
, class Period
>
31 void sleep_for(const duration
<Rep
, Period
>& d
)
33 typedef high_resolution_clock Clock
;
34 typename
Clock::time_point go
=
36 while (Clock::now() < go
)
44 strict_stopwatch
<clock_type
> sw
;
46 for ( long i
= 0; i
< j
; ++i
)
47 std::sqrt( 123.456L ); // burn some time
48 ex::sleep_for(milliseconds(100));
50 std::cout
<< "f1("<< j
<<") Elapsed time: " << sw
.elapsed() << std::endl
;
55 strict_stopwatch
<clock_type
> sw
;
60 #ifdef BOOST_CHRONO_HAS_PROCESS_CLOCKS2
61 std::cout
<< "main() Elapsed time: " << duration_cast
<duration
<process_times
<double>,boost::ratio
<1> > >(sw
.elapsed()) << std::endl
;
62 std::cout
<< "main() Elapsed time: " << duration_cast
<duration
<process_times
<nanoseconds::rep
>,boost::milli
> >(sw
.elapsed()) << std::endl
;
64 std::cout
<< "main() Elapsed time: " << sw
.elapsed() << std::endl
;