1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Chapter 8. Boost.Chrono 2.0.5</title>
6 <link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)">
10 <link rel="prev" href="atomic/porting.html" title="Porting">
11 <link rel="next" href="chrono/users_guide.html" title="User's Guide">
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
16 <td align="center"><a href="../../index.html">Home</a></td>
17 <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../more/index.htm">More</a></td>
23 <div class="spirit-nav">
24 <a accesskey="p" href="atomic/porting.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="chrono/users_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
27 <div class="titlepage"><div>
28 <div><h2 class="title">
29 <a name="chrono"></a>Chapter 8. Boost.Chrono 2.0.5</h2></div>
30 <div><div class="author"><h3 class="author">
31 <span class="firstname">Howard</span> <span class="surname">Hinnant</span>
33 <div><div class="author"><h3 class="author">
34 <span class="firstname">Beman</span> <span class="surname">Dawes</span>
36 <div><div class="author"><h3 class="author">
37 <span class="firstname">Vicente J.</span> <span class="surname">Botet Escriba</span>
39 <div><p class="copyright">Copyright © 2008 Howard Hinnant</p></div>
40 <div><p class="copyright">Copyright © 2006, 2008 Beman Dawes</p></div>
41 <div><p class="copyright">Copyright © 2009-2013 Vicente J. Botet Escriba</p></div>
42 <div><div class="legalnotice">
43 <a name="chrono.legal"></a><p>
44 Distributed under the Boost Software License, Version 1.0. (See accompanying
45 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
50 <p><b>Table of Contents</b></p>
52 <dt><span class="section"><a href="chrono.html#chrono.overview">Overview</a></span></dt>
54 <dt><span class="section"><a href="chrono.html#chrono.overview.motivation">Motivation</a></span></dt>
55 <dt><span class="section"><a href="chrono.html#chrono.overview.description">Description</a></span></dt>
57 <dt><span class="section"><a href="chrono/users_guide.html">User's Guide</a></span></dt>
59 <dt><span class="section"><a href="chrono/users_guide.html#chrono.users_guide.getting_started">Getting Started</a></span></dt>
60 <dt><span class="section"><a href="chrono/users_guide.html#chrono.users_guide.tutorial">Tutorial</a></span></dt>
61 <dt><span class="section"><a href="chrono/users_guide.html#chrono.users_guide.examples">Examples</a></span></dt>
62 <dt><span class="section"><a href="chrono/users_guide.html#chrono.users_guide.ext_references">External Resources</a></span></dt>
64 <dt><span class="section"><a href="chrono/reference.html">Reference </a></span></dt>
66 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.chrono_include_hpp">Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">include</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
67 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.cpp0x">Included on the C++11 Recommendation</a></span></dt>
68 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.io_v1">Chrono I/O V1</a></span></dt>
69 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.io">Chrono I/O V2</a></span></dt>
70 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.round">Chrono Rounding Utilities</a></span></dt>
71 <dt><span class="section"><a href="chrono/reference.html#chrono.reference.other_clocks">Other Clocks</a></span></dt>
73 <dt><span class="section"><a href="chrono/appendices.html">Appendices</a></span></dt>
75 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.history">Appendix: History</a></span></dt>
76 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.rationale">Appendix: Rationale</a></span></dt>
77 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.implementation">Appendix: Implementation
79 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.faq">Appendix: FAQ</a></span></dt>
80 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.acknowledgements">Appendix: Acknowledgements</a></span></dt>
81 <dt><span class="section"><a href="chrono/appendices.html#chrono.appendices.todo">Appendix: Future plans</a></span></dt>
92 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
93 <a name="chrono.overview"></a><a class="link" href="chrono.html#chrono.overview" title="Overview">Overview</a>
94 </h2></div></div></div>
95 <div class="toc"><dl class="toc">
96 <dt><span class="section"><a href="chrono.html#chrono.overview.motivation">Motivation</a></span></dt>
97 <dt><span class="section"><a href="chrono.html#chrono.overview.description">Description</a></span></dt>
99 <div class="blockquote"><blockquote class="blockquote"><p>
100 <span class="quote">“<span class="quote">What is time, then? If nobody asks me, I know; if I have to explain
101 it to someone who has asked me, I do not know."</span>”</span>
102 </p></blockquote></div>
103 <div class="blockquote"><blockquote class="blockquote"><p>
104 <span class="bold"><strong><span class="emphasis"><em>-- Augustine </em></span></strong></span>
105 </p></blockquote></div>
107 <a name="chrono.overview.h0"></a>
108 <span class="phrase"><a name="chrono.overview.how_to_use_this_documentation"></a></span><a class="link" href="chrono.html#chrono.overview.how_to_use_this_documentation">How
109 to Use This Documentation</a>
112 This documentation makes use of the following naming and formatting conventions.
114 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
115 <li class="listitem">
116 Code is in <code class="computeroutput"><span class="identifier">fixed</span> <span class="identifier">width</span>
117 <span class="identifier">font</span></code> and is syntax-highlighted.
119 <li class="listitem">
120 Replaceable text that you will need to supply is in <em class="replaceable"><code>italics</code></em>.
122 <li class="listitem">
123 Free functions are rendered in the code font followed by <code class="computeroutput"><span class="special">()</span></code>, as in <code class="computeroutput"><span class="identifier">free_function</span><span class="special">()</span></code>.
125 <li class="listitem">
126 If a name refers to a class template, it is specified like this: <code class="computeroutput"><span class="identifier">class_template</span><span class="special"><></span></code>;
127 that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special"><></span></code>
128 to indicate that it is a class template.
130 <li class="listitem">
131 If a name refers to a function-like macro, it is specified like this:
132 <code class="computeroutput"><span class="identifier">MACRO</span><span class="special">()</span></code>;
133 that is, it is uppercase in code font and its name is followed by <code class="computeroutput"><span class="special">()</span></code> to indicate that it is a function-like
134 macro. Object-like macros appear without the trailing <code class="computeroutput"><span class="special">()</span></code>.
136 <li class="listitem">
137 Names that refer to <span class="emphasis"><em>concepts</em></span> in the generic programming
138 sense are specified in CamelCase.
141 <div class="note"><table border="0" summary="Note">
143 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../doc/src/images/note.png"></td>
144 <th align="left">Note</th>
146 <tr><td align="left" valign="top"><p>
147 In addition, notes such as this one specify non-essential information that
148 provides additional background or rationale.
152 Finally, you can mentally add the following to any code fragments in this document:
154 <pre class="programlisting"><span class="comment">// Include all of Chrono files</span>
155 <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
157 <div class="section">
158 <div class="titlepage"><div><div><h3 class="title">
159 <a name="chrono.overview.motivation"></a><a class="link" href="chrono.html#chrono.overview.motivation" title="Motivation">Motivation</a>
160 </h3></div></div></div>
162 <a name="chrono.overview.motivation.h0"></a>
163 <span class="phrase"><a name="chrono.overview.motivation.time"></a></span><a class="link" href="chrono.html#chrono.overview.motivation.time">Time</a>
166 We all deal with time every day of our lives. We've intuitively known it
167 since birth. Thus we are all very familiar with it and believe it to be a
168 simple matter. The modeling of time in computer programs should be similarly
169 simple. The unfortunate truth is that this perceived simplicity is only skin
170 deep. Fortunately, we do not need a terribly complicated solution to meet
171 the bulk of our needs. However, overly simplistic solutions can be dangerous
172 and inefficient, and won't adapt as the computer industry evolves.
175 <span class="bold"><strong>Boost.Chrono</strong></span> implements the new time facilities
176 in C++11, as proposed in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm" target="_top"><span class="bold"><strong>N2661 - A Foundation to Sleep On</strong></span></a>. That document
177 provides background and motivation for key design decisions and is the source
178 of a good deal of information in this documentation.
181 In addition to the clocks provided by the standard proposal, <span class="bold"><strong>Boost.Chrono</strong></span>
182 provides specific process and thread clocks.
185 <a name="chrono.overview.motivation.h1"></a>
186 <span class="phrase"><a name="chrono.overview.motivation.wall_clock_versus_system_and_user_time"></a></span><a class="link" href="chrono.html#chrono.overview.motivation.wall_clock_versus_system_and_user_time">Wall
187 clock versus system and user time</a>
190 To make the timing facilities of Boost.Chrono more generally useful, the
191 library provides a number of clocks that are thin wrappers around the operating
192 system's process time API, thereby allowing the extraction of wall clock
193 time, user CPU time, and system CPU time of the process. Wall clock time
194 is the sum of CPU time and system CPU time. (On POSIX-like systems, this
195 relies on <code class="computeroutput"><span class="identifier">times</span><span class="special">()</span></code>.
196 On Windows, it relies on <code class="computeroutput"><span class="identifier">GetProcessTimes</span><span class="special">()</span></code>.)
199 <div class="section">
200 <div class="titlepage"><div><div><h3 class="title">
201 <a name="chrono.overview.description"></a><a class="link" href="chrono.html#chrono.overview.description" title="Description">Description</a>
202 </h3></div></div></div>
204 The <span class="bold"><strong>Boost.Chrono</strong></span> library provides:
207 <a name="chrono.overview.description.h0"></a>
208 <span class="phrase"><a name="chrono.overview.description.standard"></a></span><a class="link" href="chrono.html#chrono.overview.description.standard">Standard</a>
210 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
211 <li class="listitem">
212 A means to represent time durations: managed by the generic <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a> class . Examples of
213 time durations include days, <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration_typedefs" title="duration typedefs"><code class="computeroutput"><span class="identifier">minutes</span></code></a>, <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration_typedefs" title="duration typedefs"><code class="computeroutput"><span class="identifier">seconds</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration_typedefs" title="duration typedefs"><code class="computeroutput"><span class="identifier">nanoseconds</span></code></a>, which can be represented
214 with a fixed number of clock ticks per unit. All of these units of time
215 duration are united with a generic interface by the <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a> facility.
217 <li class="listitem">
218 A type for representing points in time: <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a>. A <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> represents an epoch
219 plus or minus a <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a>. The library leaves
220 epochs unspecified. A <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> is associated with
221 a <span class="emphasis"><em>clock</em></span>.
223 <li class="listitem">
224 Several clocks, some of which may not be available on a particular platform:
225 <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.system_clocks_hpp.system_clock" title="Class system_clock"><code class="computeroutput"><span class="identifier">system_clock</span></code></a>, <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.system_clocks_hpp.steady_clock" title="Class steady_clock"><code class="computeroutput"><span class="identifier">steady_clock</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.system_clocks_hpp.high_resolution_clock" title="Class high_resolution_clock"><code class="computeroutput"><span class="identifier">high_resolution_clock</span></code></a>. A clock
226 is a pairing of a <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a>, and a function which
227 returns a <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> representing <span class="emphasis"><em>now</em></span>.
231 <a name="chrono.overview.description.h1"></a>
232 <span class="phrase"><a name="chrono.overview.description.other_clocks"></a></span><a class="link" href="chrono.html#chrono.overview.description.other_clocks">Other
236 To make the timing facilities more generally useful, <span class="bold"><strong>Boost.Chrono</strong></span>
237 provides a number of clocks that are thin wrappers around the operating system's
238 time APIs, thereby allowing the extraction of wall clock time, user CPU time,
239 system CPU time spent by the process,
241 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
242 <li class="listitem">
243 <a class="link" href="chrono/reference.html#chrono.reference.other_clocks.process_cpu_clocks_hpp.process_real_cpu_clock" title="Class process_real_cpu_clock"><code class="computeroutput"><span class="identifier">process_real_cpu_clock</span></code></a>, captures
244 wall clock CPU time spent by the current process.
246 <li class="listitem">
247 <a class="link" href="chrono/reference.html#chrono.reference.other_clocks.process_cpu_clocks_hpp.process_user_cpu_clock" title="Class process_user_cpu_clock"><code class="computeroutput"><span class="identifier">process_user_cpu_clock</span></code></a>, captures
248 user-CPU time spent by the current process.
250 <li class="listitem">
251 <a class="link" href="chrono/reference.html#chrono.reference.other_clocks.process_cpu_clocks_hpp.process_system_cpu_clock" title="Class process_system_cpu_clock"><code class="computeroutput"><span class="identifier">process_system_cpu_clock</span></code></a>, captures
252 system-CPU time spent by the current process.
254 <li class="listitem">
255 A tuple-like class <a class="link" href="chrono/reference.html#chrono.reference.other_clocks.process_cpu_clocks_hpp.process_cpu_clock" title="Class process_cpu_clock"><code class="computeroutput"><span class="identifier">process_cpu_clock</span></code></a>, that captures
256 real, user-CPU, and system-CPU process times together.
258 <li class="listitem">
259 A <a class="link" href="chrono/reference.html#chrono.reference.other_clocks.thread_clock_hpp.thread_clock" title="Class thread_clock"><code class="computeroutput"><span class="identifier">thread_clock</span></code></a> thread steady clock
260 giving the time spent by the current thread (when supported by a platform).
264 Lastly, <span class="bold"><strong>Boost.Chrono</strong></span> includes <a href="http://www.boost.org/libs/typeof" target="_top">typeof</a>
265 registration for <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> to permit using emulated
266 auto with C++03 compilers.
269 <a name="chrono.overview.description.h2"></a>
270 <span class="phrase"><a name="chrono.overview.description.i_o"></a></span><a class="link" href="chrono.html#chrono.overview.description.i_o">I/O</a>
273 It provides I/O for <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a>. This I/O makes use of
274 these types much more convenient. In following the "you only pay for
275 what you use" philosophy, this extra functionality is located in a header
276 separate from <boost/chrono/chrono.hpp>, namely <boost/chrono/chrono_io.hpp>.
279 It builds on <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">ratio</span><span class="special">/</span><span class="identifier">ratio_io</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
280 to provide readable and flexible formatting and parsing for types in <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
281 This textural representation uses <a href="http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes" target="_top">SI
282 prefixes</a> whenever possible. This makes it easy for <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">milliseconds</span></code> to be represented by the text
283 "milliseconds", or a hypothetical meter class to print out "millimeter".
284 The <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.duration_hpp.duration" title="Class Template duration<>"><code class="computeroutput"><span class="identifier">duration</span></code></a> and the <a class="link" href="chrono/reference.html#chrono.reference.cpp0x.time_point_hpp.time_point" title="Class template time_point<>"><code class="computeroutput"><span class="identifier">time_point</span></code></a> i/o can be customized
285 through the new facets: <a class="link" href="chrono/reference.html#chrono.reference.io.duration_units_hpp.duration_units" title="Template Class duration_units"><code class="computeroutput"><span class="identifier">duration_units</span></code></a> and <a class="link" href="chrono/reference.html#chrono.reference.io.time_point_units_hpp.time_point_units" title="Template Class time_point_units"><code class="computeroutput"><span class="identifier">time_point_units</span></code></a>. The user can specialize
286 these facets so that the chrono i/o could be localizable. However Boost.Chrono
287 doesn't provides a complete locale solution.
290 <code class="computeroutput"><span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span></code> I/O is proposed in terms of
291 UTC timepoints, strongly guided by ISO 9899:1999, Programming languages -
292 C, ISO 9945:2003, Information Technology - Portable Operating System Interface
293 (POSIX) and ISO 8601:2004, Data elements and interchange formats - Information
294 interchange - Representation of dates and times.
297 <a name="chrono.overview.description.h3"></a>
298 <span class="phrase"><a name="chrono.overview.description.rounding_utilities"></a></span><a class="link" href="chrono.html#chrono.overview.description.rounding_utilities">Rounding
302 A few simple rounding utility functions for working with durations.
305 <a name="chrono.overview.description.h4"></a>
306 <span class="phrase"><a name="chrono.overview.description.caveat_emptor"></a></span><a class="link" href="chrono.html#chrono.overview.description.caveat_emptor">Caveat
310 The underlying clocks provided by operating systems are subject to many seemingly
311 arbitrary policies and implementation irregularities. That's a polite way
312 of saying they tend to be flakey, and each operating system or even each
313 clock has its own cruel and unusual forms of flakiness. Don't bet the farm
314 on their accuracy, unless you have become deeply familiar with exactly what
315 the specific operating system is guaranteeing, which is often very little.
320 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
321 <td align="left"><p><small>Last revised: April 17, 2017 at 02:30:28 GMT</small></p></td>
322 <td align="right"><div class="copyright-footer"></div></td>
325 <div class="spirit-nav">
326 <a accesskey="p" href="atomic/porting.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="chrono/users_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>