Public Member Functions | |
| Timer () | |
| void | start () |
| double | stop () |
| void | reset () |
| double | operator() () const |
Private Attributes | |
| double | start_time |
| double | start_time_children |
| double | cumulative_time |
| bool | running |
Use of this class is as you might expect by looking at the member functions:
Time timer; timer.start (); // do some complicated computations here ... timer.stop (); std::cout << "Elapsed time: " << timer() << " seconds."; // reset timer for the next thing it shall do timer.reset();
Alternatively, you can also restart the timer instead of resetting it. The times between successive calls to start()/ stop() will then be accumulated. The usage of this class is also explained in the step-12 and step-29 tutorial programs.
| Timer::Timer | ( | ) |
Constructor. Starts the timer at 0 sec.
| void Timer::start | ( | ) |
Re-start the timer at the point where it was stopped. This way a cumulative measurement of time is possible.
| double Timer::stop | ( | ) |
Sets the current time as next starting time and return the elapsed time in seconds.
| void Timer::reset | ( | ) |
Stop the timer if necessary and reset the elapsed time to zero.
| double Timer::operator() | ( | ) | const |
Access to the current time without disturbing time measurement. The elapsed time is returned in units of seconds.
double Timer::start_time [private] |
double Timer::start_time_children [private] |
Similar to start_time, but needed for children threads in multithread mode. Value of the user time when start() was called the last time or when the object was created and no stop() was issued in between.
For some reason (error in operating system?) the function call getrusage(RUSAGE_CHILDREN,.) gives always 0 (at least on Solaris7). Hence the Timer class still does not yet work for multithreading mode.
double Timer::cumulative_time [private] |
Accumulated time for all previous start()/stop() cycles. The time for the present cycle is not included.
bool Timer::running [private] |
Store whether the timer is presently running.
documentation generated on Fri Nov 21 07:13:38 2008 by
doxygen
1.5.6