#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.
#include <lemon/time_measure.h>
Public Member Functions | |
Timer (bool run=true) | |
Constructor. | |
Control the state of the timer | |
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. | |
Query Functions for the ellapsed time | |
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. |
Timer | ( | bool | run = true |
) | [inline] |
run | indicates whether or not the timer starts immediately. |
void reset | ( | ) | [inline] |
This function resets and stops the time counters
void start | ( | ) | [inline] |
void stop | ( | ) | [inline] |
void halt | ( | ) | [inline] |
int running | ( | ) | [inline] |
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).
operator TimeStamp | ( | ) | const [inline] |
This conversion computes the ellapsed time, therefore you can print the ellapsed time like this.
Timer t; doSomething(); std::cout << t << '\n';