Timer

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

#include "MRCPP/Timer"
class Timer

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

Public Functions

Timer(bool start_timer = true)
Parameters

start_timer[in] option to start timer immediately

Returns

New Timer object

Timer(const Timer &timer)
Parameters

timer[in] Object to copy

Returns

Copy of Timer object, including its current state

Timer &operator=(const Timer &timer)
Parameters

timer[in] Object to copy

Returns

Copy of Timer object, including its current state

void start()

Start timer from zero.

void resume()

Resume timer from previous time.

void stop()

Stop timer.

double elapsed() const
Returns

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