]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/chrono/stopwatches/example/stopwatch_example.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / example / stopwatch_example.cpp
CommitLineData
7c673cae
FG
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.
8
b32b8144 9#include <iostream>
7c673cae
FG
10#include <boost/chrono/stopwatches/strict_stopwatch.hpp>
11#include <boost/chrono/chrono_io.hpp>
12#include <boost/chrono/process_cpu_clocks.hpp>
13#include <cmath>
14
15using namespace boost::chrono;
16
17#ifdef BOOST_CHRONO_HAS_PROCESS_CLOCKS
18#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
19typedef process_cpu_clock clock_type;
20#else
21// Windows store doesn't support process_cpu_clock, default to high_resolution_clock.
22typedef high_resolution_clock clock_type;
23#endif
24#else
25typedef high_resolution_clock clock_type;
26#endif
27
28namespace ex
29{
30 template<class Rep, class Period>
31 void sleep_for(const duration<Rep, Period>& d)
32 {
33 typedef high_resolution_clock Clock;
34 typename Clock::time_point go =
35 Clock::now() + d;
36 while (Clock::now() < go)
37 {
38 }
39 }
40}
41
42int f1(long j)
43{
44 strict_stopwatch<clock_type> sw;
45
46 for ( long i = 0; i < j; ++i )
47 std::sqrt( 123.456L ); // burn some time
48 ex::sleep_for(milliseconds(100));
49
50 std::cout << "f1("<< j <<") Elapsed time: " << sw.elapsed() << std::endl;
51 return 0;
52}
53int main()
54{
55 strict_stopwatch<clock_type> sw;
56
57 f1(1000);
58 f1(2000);
59 f1(3000);
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;
63#endif
64 std::cout << "main() Elapsed time: " << sw.elapsed() << std::endl;
65 return 0;
66}