Class for measuring the cpu time and real time usage of the process.
More...
#include <lemon/time_measure.h>
|
| | Timer (bool run=true) |
| | Constructor.
|
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
|
| void | reset () |
| | Reset and stop the time counters.
|
| void | start () |
| | Start the time counters.
|
| void | stop () |
| | Stop the time counters.
|
| void | halt () |
| | Halt (i.e stop immediately) the time counters.
|
| int | running () |
| | Returns the running state of the timer.
|
| void | restart () |
| | Restart the time counters.
|
|
double | userTime () const |
| | Gives back the ellapsed user time of the process.
|
|
double | systemTime () const |
| | Gives back the ellapsed system time of the process.
|
| double | cUserTime () const |
| | Gives back the ellapsed user time of the process' children.
|
| double | cSystemTime () const |
| | Gives back the ellapsed user time of the process' children.
|
|
double | realTime () const |
| | Gives back the ellapsed real time.
|
| | operator TimeStamp () const |
| | Computes the ellapsed time.
|
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 <iostream>
int main()
{
...
doSomething();
std::cout << t << '\n';
doSomethingElse();
std::cout << t << '\n';
...
}
void restart()
Restart the time counters.
Definition time_measure.h:399
Timer( bool run=true )
Constructor.
Definition time_measure.h:299
The Timer can also be stopped and started again, so it is possible to compute collected running times.
- 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.
- Note
- If you want to measure the running time of the execution of a certain function, consider the usage of TimeReport instead.
- See also
- TimeReport
◆ Timer()
- Parameters
-
| run | indicates whether or not the timer starts immediately. |
◆ reset()
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
- restart()
◆ start()
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
- stop()
◆ stop()
◆ halt()
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
- stop()
-
restart()
-
reset()
◆ running()
This function returns the number of stop() exections that is necessary to really stop the timer. For example, the timer is running if and only if the return value is true (i.e. greater than zero).
◆ restart()
◆ cUserTime()
| double cUserTime |
( |
| ) |
const |
|
inline |
- Note
- It is always zero, as no standard facility gives it.
◆ cSystemTime()
| double cSystemTime |
( |
| ) |
const |
|
inline |
- Note
- It is always zero, as no standard facility gives it.
◆ operator TimeStamp()
This conversion computes the ellapsed time, therefore you can print the ellapsed time like this.
doSomething();
std::cout << t << '\n';