Machine learning algorithms in C++
Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Private Attributes
Timer Class Reference

A timer that keeps track of time, prints formatted time, checks if an interval has passed etc. More...

#include <Timer.hpp>

Collaboration diagram for Timer:

Public Member Functions

 Timer (unsigned int interval=0, unsigned int predictedIters=0)
 Creates an instance of a timer object. More...
 
void start ()
 Start the timer. More...
 
bool activate (unsigned int currentIter=0)
 Checks if the time interval passed in the constructor has passed. More...
 
string runningTime ()
 

Static Public Member Functions

static string prettyTime (float secondsFloat)
 Formats seconds as HH:MM:SS.mmm. More...
 

Private Types

using myClock = chrono::high_resolution_clock
 

Static Private Member Functions

static int numDigits (int32_t x)
 Counts the number of digits in an integer. More...
 
static int numDigits (char n)
 Counts the number of digits in a char. More...
 
static string zeroPad (int value, unsigned int desiredSize)
 Pads a number with 0s on the left until it reaches a desired length. More...
 

Private Attributes

unsigned int interval
 
unsigned int predictedIters
 
float lastUpdate
 
chrono::time_point< chrono::system_clock > startTime
 

Detailed Description

A timer that keeps track of time, prints formatted time, checks if an interval has passed etc.

Definition at line 18 of file Timer.hpp.

Member Typedef Documentation

◆ myClock

using Timer::myClock = chrono::high_resolution_clock
private

Definition at line 19 of file Timer.hpp.

Constructor & Destructor Documentation

◆ Timer()

Timer::Timer ( unsigned int  interval = 0,
unsigned int  predictedIters = 0 
)
inlineexplicit

Creates an instance of a timer object.

Parameters
intervalthe interval the timer will check for
predictedItersnumber of predicted iterations, so th etime can output a predicted time of conclusion

Definition at line 93 of file Timer.hpp.

Member Function Documentation

◆ activate()

bool Timer::activate ( unsigned int  currentIter = 0)
inline

Checks if the time interval passed in the constructor has passed.

Parameters
currentItercurrent iteration number, so an estimated conclusion time can be printed
Returns
true if the stipulated interval has passed, otherwise false

Definition at line 110 of file Timer.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ numDigits() [1/2]

static int Timer::numDigits ( int32_t  x)
inlinestaticprivate

Counts the number of digits in an integer.

Parameters
xan integer
Returns
number of digits in x

Definition at line 30 of file Timer.hpp.

◆ numDigits() [2/2]

static int Timer::numDigits ( char  n)
inlinestaticprivate

Counts the number of digits in a char.

Parameters
na char
Returns
number of digits in n

Definition at line 65 of file Timer.hpp.

◆ prettyTime()

static string Timer::prettyTime ( float  secondsFloat)
inlinestatic

Formats seconds as HH:MM:SS.mmm.

Parameters
secondsFloatnumber of seconds
Returns
a string separating the given seconds into hours, minutes, seconds and milliseconds

Definition at line 134 of file Timer.hpp.

Here is the caller graph for this function:

◆ runningTime()

string Timer::runningTime ( )
inline
Returns
the time since the timer has been activated

Definition at line 149 of file Timer.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

void Timer::start ( )
inline

Start the timer.

Definition at line 101 of file Timer.hpp.

Here is the caller graph for this function:

◆ zeroPad()

static string Timer::zeroPad ( int  value,
unsigned int  desiredSize 
)
inlinestaticprivate

Pads a number with 0s on the left until it reaches a desired length.

Parameters
valuethe integer value to be zero-padded
desiredSizethe desired size of the padded representation
Returns
a string with value zero-padded to desiredSize size

Definition at line 83 of file Timer.hpp.

Field Documentation

◆ interval

unsigned int Timer::interval
private

Definition at line 21 of file Timer.hpp.

◆ lastUpdate

float Timer::lastUpdate
private

Definition at line 22 of file Timer.hpp.

◆ predictedIters

unsigned int Timer::predictedIters
private

Definition at line 21 of file Timer.hpp.

◆ startTime

chrono::time_point<chrono::system_clock> Timer::startTime
private

Definition at line 23 of file Timer.hpp.


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