Clock class

A class used for measuring time.

It supports multiple precisions expressed in the enum Clock::Mode: minutes, seconds, milliseconds, microseconds, nanoseconds, ticks and nanoseprocessor time stamp. In order to use a clock, first you have to start it with the Clock::Start() method. Then just use the Clock::GetElapsed() method (or its variants) to get the elapsed time since the clock was started. In order to reset the counter, you must use Clock::Stop() and then you can start the clock again.

Public types

enum class Mode { Ticks = 0, ProcessorTimeStamp = 1, Nanoseconds = 2, Microseconds = 3, Milliseconds = 4, Seconds = 5, Minutes = 6 }

Constructors, destructors, conversion operators

Clock(Clock::Mode mode = Clock::Mode::Ticks, bool bStart = false)
Creates a new clock object with the specified precision mode.

Public functions

void SetMode(Clock::Mode mode)
Changes the precision mode.
void Start()
Starts the clock, measuring the initial time; if it has already been started, does nothing.
void Stop()
Stops the clock, reseting the initial time to 0.
auto GetElapsed() -> float
Returns the elapsed time in the specified precision measure, conserving all decimals.
auto GetElapsedTicks() -> LARGE_INTEGER
Returns the elapsed time in ticks (regardles of the clock mode).
auto GetElapsedTime() -> LARGE_INTEGER
Returns the elapsed time in the specified precision measure, rounded to the closest integer.

Protected variables

LARGE_INTEGER mStartTime
LARGE_INTEGER field_8
Clock::Mode mMode
The mode (precision) with which the time is measured.
float mfMeasurePerTick
Derived from mMode, how many units of measurement (seconds, nanoseconds, etc) are equal to 1 tick.

Enum documentation

enum class Clock::Mode

Enumerators
Ticks

Uses QueryPerformanceCounter to measure time (in ticks).

ProcessorTimeStamp

Uses __rdtsc (Read Time Stamp Counter) to get the current time (in ticks?), instead of QueryPerformanceCounter.

Nanoseconds

Measures the time with nanosecond precision (1 second = 10e9 nanoseconds).

Uses QueryPerformanceCounter to measure time.

Microseconds

Measures the time with microsecond precision (1 second = 10e6 microseconds).

Uses QueryPerformanceCounter to measure time.

Milliseconds

Measures the time with milliseconds precision (1 second = 10e3 milliseconds).

Uses QueryPerformanceCounter to measure time.

Seconds

Measures the time with seconds precision.

Uses QueryPerformanceCounter to measure time.

Minutes

Measures the time with minute precision (60 seconds = 1 minute).

Uses QueryPerformanceCounter to measure time.

Function documentation

Clock::Clock(Clock::Mode mode = Clock::Mode::Ticks, bool bStart = false)

Creates a new clock object with the specified precision mode.

Parameters
mode The precision with which the clock will measure time.
bStart [Optional] If true, the clock will start counting time. False by default.

Optionally, you can make the clock start counting.

void Clock::SetMode(Clock::Mode mode)

Changes the precision mode.

Parameters
mode The precision with which the clock will measure time.

void Clock::Stop()

Stops the clock, reseting the initial time to 0.

After using stop, the clock can be started again using Clock::Start().