Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
larcorealg
test
TestUtils
StopWatch_test.cc
Go to the documentation of this file.
1
/**
2
* @file StopWatch_test.cc
3
* @brief Test for the StopWatch class
4
* @author Gianluca Petrillo (petrillo@fnal.gov)
5
* @date July 3, 2016
6
* @see StopWatch.h
7
*
8
* This test instantiates a stopwatch and makes some queries.
9
*
10
* It is not an actual test in that there is no automatic verification of the
11
* results (which would be somehow problematic given that times are not
12
* completely reproducible).
13
*
14
*/
15
16
// our libraries
17
#include "
larcorealg/TestUtils/StopWatch.h
"
18
19
// C/C++ standard libraries
20
#include <chrono>
21
#include <ratio>
22
#include <thread>
// std::this_thread
23
#include <iostream>
24
25
26
void
wait
(
std::chrono::milliseconds
dur) {
27
std::cout <<
" <waiting for "
<< dur.count() <<
" ms>"
<<
std::endl
;
28
std::this_thread::sleep_for(dur);
29
}
// wait()
30
31
32
int
main
(
int
/* argc */
,
char
**
/* argv */
) {
33
34
std::chrono::milliseconds
WaitFor { 250 };
35
36
std::cout <<
"Creating stop watch..."
<<
std::endl
;
37
testing::StopWatch<std::chrono::duration<double>
, std::chrono::system_clock> timer;
38
std::cout <<
" - elapsed time so far: "
<< timer.
elapsed
() <<
" s; partial time: "
<< timer.
partial
() <<
" s"
<<
std::endl
;
39
40
wait
(WaitFor);
41
std::cout <<
" - elapsed time so far: "
<< timer.
elapsed
() <<
" s ("
<< timer.
elapsed
<std::micro>() <<
" us); partial time: "
<< timer.
partial
<std::micro>() <<
" us"
<<
std::endl
;
42
43
std::cout <<
"Stopping watch"
<<
std::endl
;
44
timer.
stop
();
45
wait
(WaitFor);
46
std::cout <<
" - elapsed time so far: "
<< timer.
elapsed
() <<
" s ("
<< timer.
elapsed
<
std::chrono::microseconds
>() <<
" us); partial time: "
<< timer.
partial
<
std::chrono::microseconds
>() <<
" us"
<<
std::endl
;
47
48
std::cout <<
"Resuming watch"
<<
std::endl
;
49
timer.
resume
();
50
wait
(WaitFor);
51
std::cout <<
" - elapsed time so far: "
<< timer.
elapsed
() <<
" s ("
<< timer.
elapsed
<
std::chrono::seconds
>() <<
" s); partial time: "
<< timer.
partial
<
std::chrono::seconds
>() <<
" s"
<<
std::endl
;
52
53
std::cout <<
"Restarting watch"
<<
std::endl
;
54
timer.
restart
();
55
wait
(WaitFor);
56
std::cout <<
" - elapsed time so far: "
<< timer.
elapsed
() <<
" s ("
<< timer.
elapsed
<
std::chrono::milliseconds
>() <<
" ms); partial time: "
<< timer.
partial
<
std::chrono::milliseconds
>() <<
" ms"
<<
std::endl
;
57
58
59
return
0;
60
}
// main()
wait
void wait(std::chrono::milliseconds dur)
Definition:
StopWatch_test.cc:26
testing::StopWatch::stop
void stop()
Pauses the watch.
Definition:
StopWatch.h:236
testing::StopWatch::elapsed
ElapsedTime_t elapsed() const
Returns the total time spent running since the last restart.
Definition:
StopWatch.h:254
util::quantities::microseconds
microsecond microseconds
Alias for common language habits.
Definition:
spacetime.h:122
StopWatch.h
testing::StopWatch::partial
ElapsedTime_t partial() const
Returns the time spent running since the last resume.
Definition:
StopWatch.h:264
testing::StopWatch::restart
void restart()
Restarts the watch; previous time is forgotten.
Definition:
StopWatch.h:218
main
int main()
Definition:
StopWatch_test.cc:32
testing::StopWatch
Provides time interval measurements.
Definition:
StopWatch.h:79
util::quantities::seconds
second seconds
Alias for common language habits.
Definition:
spacetime.h:88
util::quantities::milliseconds
millisecond milliseconds
Alias for common language habits.
Definition:
spacetime.h:105
testing::StopWatch::resume
void resume()
Resumes the run of the watch; previous time is preserved.
Definition:
StopWatch.h:227
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11