Timer

MRCPP comes with a timer class which can be used by the host program:

#include "MRCPP/Timer"
class mrcpp::Timer

Records wall time between the execution of two lines of source code.

Public Functions

Timer(bool start_timer = true)

Return

New Timer object

Parameters
  • [in] start_timer: option to start timer immediately

Timer(const Timer &timer)

Return

Copy of Timer object, including its current state

Parameters
  • [in] timer: Object to copy

Timer &operator=(const Timer &timer)

Return

Copy of Timer object, including its current state

Parameters
  • [in] timer: Object to copy

void start()

Start timer from zero.

void resume()

Resume timer from previous time.

void stop()

Stop timer.

double elapsed() const

Return

Current elapsed time, in seconds

Examples

The timer records wall (human) time, not CPU user time. The clock will by default start immediately after construction, and will keep running until explicitly stopped. The elapsed time can be evaluated while clock is running:

mrcpp::Timer timer;                     // This will start the timer
mrcpp::project(prec, tree, func);       // Do some work
double t = timer.elapsed();             // Get time since clock started while still running

The timer can also be started explicitly at a later stage after construction, as well as explicitly stopped after the work is done. Then the elapsed() function will return the time spent between start() and stop():

mrcpp::Timer timer(false);              // This will not start the timer
timer.start();                          // This will start the timer
mrcpp::project(prec, tree, func);       // Do some work
timer.stop();                           // This will stop the timer
double t = timer.elapsed();             // Get time spent between start and stop