Timer
Declared in lemon/time_measure.h, in the group Time Measuring and Counting; the same class on the Doxygen site.
-
class Timer
Class for measuring the cpu time and real time usage of the process. It is quite easy-to-use, here is a short example.
#include <lemon/time_measure.h> #include <iostream> int main() { ... Timer t; doSomething(); std::cout << t << '\n'; t.restart(); doSomethingElse(); std::cout << t << '\n'; ... }
The Timer can also be stopped and started again, so it is possible to compute collected running times.
See also
Note
If you want to measure the running time of the execution of a certain function, consider the usage of TimeReport instead.
Warning
Depending on the operation system and its actual configuration the time counters have a certain (10ms on a typical Linux system) granularity. Therefore this tool is not appropriate to measure very short times. Also, if you start and stop the timer very frequently, it could lead to distorted results.
Subclassed by TimeReport
Control the State of the Timer
Basically a Timer can be either running or stopped, but it provides a bit finer control on the execution. The Timer also counts the number of
-
inline void reset()
Reset and stop the time counters.
start() executions, and it stops only after the same amount (or more) stop()s. This can be useful e.g. to compute the running time of recursive functions. This function resets and stops the time counters
See also
-
inline void start()
Start the time counters.
This function starts the time counters.
If the timer is started more than ones, it will remain running until the same amount of stop() is called.
See also
-
inline void stop()
Stop the time counters.
This function stops the time counters. If start() was executed more than once, then the same number of stop() execution is necessary the really stop the timer.
See also
See also
See also
See also
-
inline void halt()
Halt (i.e stop immediately) the time counters.
This function stops immediately the time counters, i.e.
t.halt()is a faster equivalent of the following.while( t.running() ) t.stop()
See also
See also
See also
Query Functions for the Ellapsed Time
-
inline double userTime() const
Gives back the ellapsed user time of the process.
-
inline double systemTime() const
Gives back the ellapsed system time of the process.
-
inline double cUserTime() const
Gives back the ellapsed user time of the process’ children.
Note
It is always zero, as no standard facility gives it.
-
inline double cSystemTime() const
Gives back the ellapsed user time of the process’ children.
Note
It is always zero, as no standard facility gives it.
-
inline double realTime() const
Gives back the ellapsed real time.
Public Functions
-
inline Timer( bool run = true )
Constructor.
- Parameters:
run – indicates whether or not the timer starts immediately.
-
inline void reset()