#include <mcllib/MCTimer.h>
Public Member Functions | |
void | elapse (mcinterval_t ms) |
If ms milli-seconds have already elapsed it does not wait. | |
mcinterval_t | getElapsed () const |
Obtain the number of milli-seconds since the timer was created or since it was reset by either a call to the elapse() method (which implicitly calls reset()) or by an explicit call to the reset() method. | |
MCTimer () | |
Construct a timer with current system value. | |
mcinterval_t | reset () |
Obtain the number of mill-seconds since the timer was created or since it was reset. | |
void | wait (mcinterval_t ms) const |
Wait until a number of milliseconds have elapsed since the timer was created or reset. |
Use for calculating elapsed times between operations. Example
MCTimer t; ... do some activity ... cout << "That took " << t.getElapsed() << " milliseconds" << endl;(use reset instead of getElapsed if you are doing it repeatedly) or for implemeting "polling" types of operations e.g.
MCTimer t; while (...) { ... do some activity ... // if the activity took less that 5.000 secs sleep until // 5.000 secs since the loop started t.elapse(5000);} The use of millisecond as the unit gives a maximum interval of about 24 days.
|
If ms milli-seconds have already elapsed it does not wait. Wait until a number of milliseconds have elapsed since the timer was created or reset. Unlike the wait() method, the timer is reset to the current system value. If ms milli-seconds have already elapsed the call returns immediately without waiting.
|
|
Obtain the number of milli-seconds since the timer was created or since it was reset by either a call to the elapse() method (which implicitly calls reset()) or by an explicit call to the reset() method. The value of the timer is not changed.
|
|
Obtain the number of mill-seconds since the timer was created or since it was reset. The timer is reset to the current system value.
|
|
Wait until a number of milliseconds have elapsed since the timer was created or reset. The timer is not reset - waiting again for the same or lower time will return immediately. If ms milli-seconds have already elapsed the call returns immediately without waiting.
|