Functions
StopWatch_test.cc File Reference
#include "TestUtils/StopWatch.h"
#include <chrono>
#include <ratio>
#include <thread>
#include <iostream>

Go to the source code of this file.

Functions

void waitgst (std::chrono::milliseconds dur)
 
int main ()
 

Function Documentation

int main ( void  )

Definition at line 32 of file StopWatch_test.cc.

32  {
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
39  << " - elapsed time so far: "
40  << timer.elapsed()
41  << " s; partial time: "
42  << timer.partial()
43  << " s"
44  << std::endl;
45 
46  waitgst(WaitFor);
47  std::cout
48  << " - elapsed time so far: "
49  << timer.elapsed()
50  << " s ("
51  << timer.elapsed<std::micro>()
52  << " us); partial time: "
53  << timer.partial<std::micro>()
54  << " us"
55  << std::endl;
56 
57  std::cout
58  << "Stopping watch"
59  << std::endl;
60  timer.stop();
61  waitgst(WaitFor);
62  std::cout
63  << " - elapsed time so far: "
64  << timer.elapsed()
65  << " s ("
67  << " us); partial time: "
69  << " us"
70  << std::endl;
71 
72  std::cout
73  << "Resuming watch"
74  << std::endl;
75  timer.resume();
76  waitgst(WaitFor);
77  std::cout
78  << " - elapsed time so far: "
79  << timer.elapsed()
80  << " s ("
81  << timer.elapsed<std::chrono::seconds>()
82  << " s); partial time: "
83  << timer.partial<std::chrono::seconds>()
84  << " s"
85  << std::endl;
86 
87  std::cout
88  << "Restarting watch"
89  << std::endl;
90  timer.restart();
91  waitgst(WaitFor);
92  std::cout
93  << " - elapsed time so far: "
94  << timer.elapsed()
95  << " s ("
97  << " ms); partial time: "
99  << " ms"
100  << std::endl;
101 
102 
103  return 0;
104 } // main()
void stop()
Pauses the watch.
Definition: StopWatch.h:236
ElapsedTime_t elapsed() const
Returns the total time spent running since the last restart.
Definition: StopWatch.h:254
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
ElapsedTime_t partial() const
Returns the time spent running since the last resume.
Definition: StopWatch.h:264
void restart()
Restarts the watch; previous time is forgotten.
Definition: StopWatch.h:218
Provides time interval measurements.
Definition: StopWatch.h:79
second seconds
Alias for common language habits.
Definition: spacetime.h:88
millisecond milliseconds
Alias for common language habits.
Definition: spacetime.h:105
void resume()
Resumes the run of the watch; previous time is preserved.
Definition: StopWatch.h:227
void waitgst(std::chrono::milliseconds dur)
QTextStream & endl(QTextStream &s)
void waitgst ( std::chrono::milliseconds  dur)

Definition at line 26 of file StopWatch_test.cc.

26  {
27  std::cout << " <waiting for " << dur.count() << " ms>" << std::endl;
28  std::this_thread::sleep_for(dur);
29 } // waitgst()
QTextStream & endl(QTextStream &s)