All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
StopWatch_test.cc File Reference

Test for the StopWatch class. More...

#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 **)
 

Detailed Description

Test for the StopWatch class.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
July 3, 2016
See Also
StopWatch.h

This test instantiates a stopwatch and makes some queries.

It is not an actual test in that there is no automatic verification of the results (which would be somehow problematic given that times are not completely reproducible).

Definition in file StopWatch_test.cc.

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
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
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
ElapsedTime_t partial() const
Returns the time spent running since the last resume.
void resume()
Resumes the run of the watch; previous time is preserved.
Definition: StopWatch.h:227
ElapsedTime_t elapsed() const
Returns the total time spent running since the last restart.
BEGIN_PROLOG could also be cout
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()
BEGIN_PROLOG could also be cout