3es  0.7
tes::Timer Class Reference

A high precision timer implementation. More...

#include <3estimer.h>

Public Member Functions

 Timer ()
 Constructor. Verifies data size.
 
void start ()
 Starts the timer by recording the current time.
 
long long restart ()
 Restarts the timer and returns the time elapsed until this call. More...
 
void mark ()
 Records the current time as the end time for elapsed calls.
 
bool hasElapsedMs (long long milliseconds)
 Checks to see if the given time interval has elapsed. More...
 
long long elapsedNowMS ()
 Return the time elapsed now. More...
 
long long elapsedNowUS ()
 Return the time elapsed now. More...
 
void elapsed (unsigned int &seconds, unsigned int &milliseconds, unsigned int &microseconds) const
 Calculates the elapsed time between start() and mark(). More...
 
void elapsed (Timing &timing) const
 Calculates the elapsed time between start() and mark(). More...
 
void elapsedNow (Timing &timing)
 Marks the current end time (mark()) and calculates the elapsed time since start(). More...
 
double elapsedS () const
 Determines the elapsed time between recorded start and mark times. More...
 
long long elapsedMS () const
 Determines the elapsed time between recorded start and mark times. More...
 
long long elapsedUS () const
 Determines the elapsed time between recorded start and mark times. More...
 

Static Public Member Functions

static void split (long long timeNs, Timing &timing)
 Splits a nanoseconds value. More...
 
static void split (long long timeUs, unsigned int &seconds, unsigned int &milliseconds, unsigned int &microseconds)
 Splits a microsecond value into seconds and milliseconds. More...
 

Detailed Description

A high precision timer implementation.

Actual precision is platform dependent.

On Windows, uses QueryPerformanceCounter(). Unix based platforms use gettimeofday().

General usage is to call start() at the start of timing and mark() at the end. Various elapsed methods may be used to determine the elapsed time.

A timer may be restarted by calling start() and mark() again. A timer cannot be paused.

Member Function Documentation

◆ elapsed() [1/2]

void tes::Timer::elapsed ( unsigned int &  seconds,
unsigned int &  milliseconds,
unsigned int &  microseconds 
) const

Calculates the elapsed time between start() and mark().

The result is broken up into seconds, ms and us.

Parameters
[out]secondsThe number of whole seconds elapsed.
[out]millisecondsThe number of whole milliseconds elapsed [0, 999].
[out]microsecondsThe number of whole microseconds elapsed [0, 999].

◆ elapsed() [2/2]

void tes::Timer::elapsed ( Timing timing) const

Calculates the elapsed time between start() and mark().

The result is broken up into seconds, ms and us.

Parameters
[out]timingElapsed timing written here.

◆ elapsedMS()

long long tes::Timer::elapsedMS ( ) const

Determines the elapsed time between recorded start and mark times.

Elapsed time is returned in whole milliseconds.

Undefined before calling start() and mark().

Returns
The elapsed time in milliseconds.

◆ elapsedNow()

void tes::Timer::elapsedNow ( Timing timing)

Marks the current end time (mark()) and calculates the elapsed time since start().

The result is broken up into seconds, ms and us.

Parameters
[out]timingElapsed timing written here.

◆ elapsedNowMS()

long long tes::Timer::elapsedNowMS ( )

Return the time elapsed now.

Similar to calling mark() then elapsedMS(). This destroys information recorded on the last mark() call.

Returns
The time elapsed to now in milliseconds.

◆ elapsedNowUS()

long long tes::Timer::elapsedNowUS ( )

Return the time elapsed now.

Similar to calling mark() then elapsedUS(). This destroys information recorded on the last mark() call.

Returns
The time elapsed to now in microseconds.

◆ elapsedS()

double tes::Timer::elapsedS ( ) const

Determines the elapsed time between recorded start and mark times.

Elapsed time is returned in seconds with a fractional component.

Undefined before calling start() and mark().

Returns
The elapsed time in seconds.

◆ elapsedUS()

long long tes::Timer::elapsedUS ( ) const

Determines the elapsed time between recorded start and mark times.

Elapsed time is returned in whole microseconds. Precision may be less than a microsecond depending on the platform.

Undefined before calling start() and mark().

Returns
The elapsed time in microseconds.

◆ hasElapsedMs()

bool tes::Timer::hasElapsedMs ( long long  milliseconds)

Checks to see if the given time interval has elapsed.

This destroys information recorded on the last mark() call.

Parameters
millisecondsThe elapsed timer interval to check (milliseconds).
Returns
True if milliseconds has elapsed since start() was called.

◆ restart()

long long tes::Timer::restart ( )

Restarts the timer and returns the time elapsed until this call.

Returns
The time elapsed (ms) from the last start() or restart() call to this call.

◆ split() [1/2]

static void tes::Timer::split ( long long  timeNs,
Timing timing 
)
static

Splits a nanoseconds value.

Parameters
timeNsThe nanoseconds only value to split.
[out]timingElapsed timing written here.

◆ split() [2/2]

static void tes::Timer::split ( long long  timeUs,
unsigned int &  seconds,
unsigned int &  milliseconds,
unsigned int &  microseconds 
)
static

Splits a microsecond value into seconds and milliseconds.

Parameters
timeUsThe microseconds only value to split.
secondsThe number of whole seconds in timeUs
millisecondsThe number of whole milliseconds in timeUs.
microsecondsThe remaining microseconds left in timeUs. Always < 1000.

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