#include "timer.h"

class Timer

This class implements a simple start/stop timer that can tell you how much time has elapsed since it was started. Typical usage of this class looks like this:
   Timer tim;
   tim.start();
   ... run some code that takes a while ...
   tim.stop();
   cout << "The code took " << tim.elapsed() << "ms to finish." << endl;
Constructor
Timer() Creates a timer object that has not yet been started.
Timer(autostart) Creates a timer object and optionally starts it.
Methods
elapsed() Returns the number of milliseconds since the timer was started.
isStarted() Returns whether the timer has been started.
start() Starts the timer.
stop() Stops the timer.

Constructor detail


Timer();
Creates a timer object that has not yet been started. You can start it afterward by calling its start function.

Usage:

Timer timer();

Timer(bool autostart);
Creates a timer object and optionally starts it, if true is passed.

Usage:

Timer timer(true);   // timer will start immediately

Method detail


long elapsed();
Returns the number of milliseconds since the last time 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();
Returns true if this timer has been started and has not yet been stopped.

Usage:

if (timer.isStarted()) { ...

void start();
Starts the timer. The timer will capture the current time and remember it so that when you later call stop or elapsed, the amount of time will be relative to this start time.

Usage:

timer.start();

void stop();
Stops the timer. After stopping the timer, future calls to elapsed will return the number of milliseconds between when start was called and when stop was called.

Usage:

timer.stop();