ug4
ug::Stopwatch Class Reference

Stopwatch class for quickly taking times. More...

#include <stopwatch.h>

Public Member Functions

double ms ()
 Returns milliseconds since call of start. More...
 
void start ()
 Starts the Stopwatch. More...
 
void stop ()
 Stops the Stopwatch. More...
 
 Stopwatch ()
 Default constructor for the Stopwatch. More...
 

Private Attributes

std::chrono::high_resolution_clock::time_point begin
 Time point of the start of Stopwatch. More...
 
bool bRunning
 Flag indicating state of Stopwatch. More...
 
std::chrono::high_resolution_clock::time_point end
 Number of microseconds since begin. More...
 

Friends

std::ostream & operator<< (std::ostream &out, Stopwatch &s)
 Prints number of milliseconds since call of start() to ostream. More...
 

Detailed Description

Stopwatch class for quickly taking times.

Depending on CXX11 flag, two different versions are compiled. If CXX11=ON, std::chrono from C++11's STL is used providing high resolution (microseconds) time measuring. Otherwise std::ctime is used providing millisecond resolution.

Note
If CXX11=OFF timings shorter than 100ms seem to be rather inaccurate.

Constructor & Destructor Documentation

◆ Stopwatch()

ug::Stopwatch::Stopwatch ( )
inline

Default constructor for the Stopwatch.

References begin, bRunning, end, and ug::get_clock_s().

Member Function Documentation

◆ ms()

double ug::Stopwatch::ms ( )
inline

Returns milliseconds since call of start.

Returns the amount of milliseconds passed between calls of Stopwatch::start() and Stopwatch::stop() or this function call.

Note
If compiled with CXX11=ON returned milliseconds have microsecond resolution.
Returns
milliseconds

References begin, bRunning, end, and ug::get_clock_s().

◆ start()

void ug::Stopwatch::start ( )
inline

Starts the Stopwatch.

References begin, bRunning, and ug::get_clock_s().

◆ stop()

void ug::Stopwatch::stop ( )
inline

Stops the Stopwatch.

References bRunning, end, and ug::get_clock_s().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
Stopwatch s 
)
friend

Prints number of milliseconds since call of start() to ostream.

Pretty prints the amount of milliseconds passed between calls of Stopwatch::start() and Stopwatch::stop() or this function call to the specified std::ostream.

Parameters
[out]outstd::ostream to print number of milliseconds to
[in]swa Stopwatch instance (usualy 'this')

Member Data Documentation

◆ begin

std::chrono::high_resolution_clock::time_point ug::Stopwatch::begin
private

Time point of the start of Stopwatch.

Referenced by ms(), start(), and Stopwatch().

◆ bRunning

bool ug::Stopwatch::bRunning
private

Flag indicating state of Stopwatch.

Referenced by ms(), start(), stop(), and Stopwatch().

◆ end

std::chrono::high_resolution_clock::time_point ug::Stopwatch::end
private

Number of microseconds since begin.

Referenced by ms(), stop(), and Stopwatch().


The documentation for this class was generated from the following file: