]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/chrono/doc/stopwatches/motivation.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / chrono / doc / stopwatches / motivation.qbk
CommitLineData
7c673cae
FG
1[/
2 / Copyright (c) 2009-20012 Vicente J. Botet Escriba
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8
9[/==================]
10[/section Motivation]
11[/==================]
12
13
14[heading Measuring elapsed time]
15
16Knowing how long a program, a function or a specific code block takes to execute is useful in both test and production environments.
17__Boost_Chrono introduces the __strict_stopwatch_concept concept which is a mechanism to measure the elapsed time.
18__strict_stopwatch`<>` is the basic model of __strict_stopwatch_concept.
19
20[heading Reporting elapsed time]
21
22It is often necessary to report elapsed time on a user display or in a log file. __stopwatch_reporter provides a runtime reporting mechanism for this purpose which can be invoked in just one line of code.
23
24 using namespace boost::chrono;
25 int main()
26 {
27 __stopwatch_reporter<__stopwatch<__process_cpu_clocks> > _;
28 // ...
29 }
30
31Will produce the following output
32
33 real 0.034s, cpu 0.031s (93.0%), user 0.031s, system 0.000s
34
35As this is one of the expression more commonly use, the library provides a __stopclock shortcut so the preceding can be written as
36
37 int main()
38 {
39 __stopclock<__process_cpu_clocks> _;
40 // ...
41 }
42
43