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

Go to the source code of this file.

Functions

void wait (std::chrono::milliseconds dur)
 
int main (int, char **)
 

Function Documentation

int main ( int  ,
char **   
)

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 << " - 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()
void wait(std::chrono::milliseconds dur)
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
QTextStream & endl(QTextStream &s)
void wait ( 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 } // wait()
QTextStream & endl(QTextStream &s)