class Timer
Timer tim; tim.start(); ... run some code that takes a while ... tim.stop(); cout << "The code took " << tim.elapsed() << "ms to finish." << endl;
This class distinguishes itself from GTimer
in that it is more of a stopwatch that can tell you how much time has elapsed since a given starting point,
while GTimer
is a class meant for use in graphical applications that generates timer events at specified intervals.
Available since: 2014/02/01 version of C++ library
Constructor | |
Creates a timer object that has not yet been started. | |
Creates a timer object and optionally starts it. | |
Methods | |
Returns the number of milliseconds since the timer was started. | |
Returns whether the timer has been started. | |
Starts the timer. | |
Stops the timer. |
Timer();
start
function.
Usage:
Timer timer();
Timer(bool autostart);
true
is passed.
Usage:
Timer timer(true); // timer will start immediately
long elapsed();
start
was called.
If the timer is still active (if stop
has not been called), this number will be continually growing as time passes.
If stop
has already been called, this function will return the number of milliseconds between when start
was called and when stop
was called.
Returns 0 if the timer was never started.
Usage:
long elapsedMS = timer.elapsed();
bool isStarted();
true
if this timer has been started and has not yet been stopped.
Usage:
if (timer.isStarted()) { ...
void start();
stop
or elapsed
, the amount of time will be relative to this start time.
Usage:
timer.start();
void stop();
elapsed
will return the number of milliseconds between when start
was called and when stop
was called.
Usage:
timer.stop();