-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrono_io_ex1.cpp
More file actions
115 lines (91 loc) · 3.74 KB
/
chrono_io_ex1.cpp
File metadata and controls
115 lines (91 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// io_ex1.cpp ----------------------------------------------------------//
// Copyright 2010 Howard Hinnant
// Copyright 2010 Vicente J. Botet Escriba
// Copyright (c) Microsoft Corporation 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
/*
This code was adapted by Vicente J. Botet Escriba from Hinnant's html
documentation. Many thanks to Howard for making his code available under the
Boost license.
*/
#define BOOST_CHRONO_VERSION 2
#include <boost/chrono/chrono_io.hpp>
#include <boost/chrono/config.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
#include <boost/chrono/system_clocks.hpp>
#include <boost/chrono/thread_clock.hpp>
#include <iostream>
int main()
{
using std::cout;
using namespace boost;
using namespace boost::chrono;
cout << "milliseconds(1) = " << milliseconds(1) << '\n';
cout << "milliseconds(3) + microseconds(10) = "
<< milliseconds(3) + microseconds(10) << '\n';
cout << "hours(3) + minutes(10) = " << hours(3) + minutes(10) << '\n';
typedef duration<long long, ratio<1, 2500000000ULL> > ClockTick;
cout << "ClockTick(3) + nanoseconds(10) = "
<< ClockTick(3) + nanoseconds(10) << '\n';
//========================================
cout << "\nSet cout to use short names:\n";
#if BOOST_CHRONO_VERSION == 2
cout << duration_fmt(duration_style::symbol);
#else
cout << duration_short;
#endif
cout << "milliseconds(3) + microseconds(10) = "
<< milliseconds(3) + microseconds(10) << '\n';
cout << "hours(3) + minutes(10) = " << hours(3) + minutes(10) << '\n';
cout << "ClockTick(3) + nanoseconds(10) = "
<< ClockTick(3) + nanoseconds(10) << '\n';
cout << "\nsystem_clock::now() = " << system_clock::now() << '\n';
//>>>>>>>> system_clock::now() = 2018-11-01 20:40:04.126208000 +0100
#if BOOST_CHRONO_VERSION == 2
cout << "\nsystem_clock::now() = " << time_fmt(chrono::timezone::local)
<< system_clock::now() << '\n';
//>>>>> steady_clock::now() = 3622313527196 ns since boot
cout << "\nsystem_clock::now() = "
<< time_fmt(chrono::timezone::local, "%Y/%m/%d")
<< system_clock::now() << '\n';
//>>>>> system_clock::now() = 2018/11/01
#endif
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
cout << "steady_clock::now() = " << steady_clock::now() << '\n';
//>>>>>> steady_clock::now() = 3622313527196 ns since boot
#endif
#if BOOST_CHRONO_VERSION == 2
//========================================
cout << "\nSet cout to use long names:\n"
<< duration_fmt(duration_style::prefix)
<< "high_resolution_clock::now() = " << high_resolution_clock::now()
<< '\n';
//>>>>>> high_resolution_clock::now() = 3622313562363 nanoseconds since
// boot
#else
cout << "\nSet cout to use long names:\n"
<< duration_long
<< "high_resolution_clock::now() = " << high_resolution_clock::now()
<< '\n';
#endif
#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
cout << "\nthread_clock::now() = " << thread_clock::now() << '\n';
//>>>>>> thread_clock::now() = 5556000 nanoseconds since thread start-up
#endif
#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
cout << "\nprocess_real_cpu_clock::now() = "
<< process_real_cpu_clock::now() << '\n';
//>>>>> process_real_cpu_clock::now() = 1541101204120000000 nanoseconds
// since process start-up
# if BOOST_PLAT_WINDOWS_DESKTOP
cout << "\nprocess_user_cpu_clock::now() = "
<< process_user_cpu_clock::now() << '\n';
cout << "\nprocess_system_cpu_clock::now() = "
<< process_system_cpu_clock::now() << '\n';
cout << "\nprocess_cpu_clock::now() = " << process_cpu_clock::now()
<< '\n';
# endif
#endif
return 0;
}