Module: Essential Tools Module Group: Miscellaneous Classes
Does not inherit
elapsedMicroseconds() elapsedMilliseconds() |
elapsedSeconds() elapsedTime() |
reset() RWClockTimer() |
start() stop() |
#include <rw/timer.h> RWClockTimer timer;
This class measures elapsed wall clock time. The timer has two states: running and stopped. The timer measures the total amount of time spent in the "running" state since it was either constructed or reset. RWClockTimer has the same interface as RWTimer.
The timer is put into the "running" state by calling member function start(). It is put into the "stopped" state by calling stop().
None
This example prints out the amount of time used:
#include <iostream> #include <rw/timer.h> #include <rw/tools/datetime.h> int main() { std::cout << "Starting the timer ...\n"; std::cout << "... and looping for 5 seconds using RWDateTime as clock ...\n"; RWTimer t; t.start(); // Start the timer // Loop for 5 seconds: RWDateTime tmp (RWDateTime::setCurrentTime); for (; (RWDateTime::now () - tmp) < 5000;) { } t.stop(); // Stop the timer std::cout << "The elapsed time was: \n"; std::cout << "System : " << double (t.time (RWTimer::SYSTEM)) / 1000000.0F << " seconds.\n"; std::cout << "User : " << double (t.time (RWTimer::USER)) / 1000000.0F << " seconds.\n"; std::cout << "Total : " << double (t.time (RWTimer::USER | RWTimer::SYSTEM)) / 1000000.0F << " seconds.\n"; return 0; }
Program output:
Starting the timer ... ... and looping for 5 seconds using RWDateTime as clock ... The elapsed time was: System : 0.004 seconds. User : 4.99524 seconds. Total : 4.99924 seconds.
The program output is a number less than 5 since RWTime has only second accuracy (milliseconds are truncated) while RWClockTimer has millisecond accuracy. (RWTime is deprecated. For millisecond accuracy, use RWDateTime.
RWClockTimer();
Constructs a new timer. The timer will not start running until start() is called.
rwint64 elapsedSeconds() const; rwint64 elapsedMilliseconds() const; rwint64 elapsedMicroseconds() const;
These three functions return the number of seconds, milliseconds, or microseconds respectively, that have elapsed while the timer was in the running state.
double
elapsedTime() const;
Returns the amount of time in seconds that has accumulated while the timer was in the running state.
void
reset();
Resets (and stops) the timer.
void
start();
Puts the timer in the "running" state. Time accumulates while in this state.
void
stop();
Puts the timer in the "stopped" state. Time will not accumulate while in this state.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.