Simbody  3.6
High-Resolution Elapsed Time Measurement and Sleep

These functions provide access to the system's high resolution interval timer, and highest precision sleep facility for unscheduling a thread until it is needed at a specific later time. More...

Functions

long long SimTK::realTimeInNs ()
 Return current time on the high-resolution interval timer in nanoseconds, as a 64-bit integer count. More...
 
double SimTK::realTime ()
 Return current time on the high-resolution interval timer in seconds. More...
 
void SimTK::sleepInNs (const long long &ns)
 Sleep for the indicated number of nanoseconds, with the actual precision system dependent but intended to be the best achievable, hopefully less than 5ms in all cases. More...
 
void SimTK::sleepInSec (const double &seconds)
 Sleep for the indicated number of seconds, with the actual precision system dependent but intended to be the best achievable, hopefully less than 5ms in all cases. More...
 

Detailed Description

These functions provide access to the system's high resolution interval timer, and highest precision sleep facility for unscheduling a thread until it is needed at a specific later time.

The interval timer measures elapsed time from some arbitrary starting point (typically since the system was last booted). It is expected that this timer provides very precise measurement of short time intervals, but cannot be depended upon to measure very long periods without drifting. That is, it may not be synchronized to the system time of day.

Generally it is most convenient to measure intervals as a floating point number of seconds, however this provides a variable amount of precision as the absolute value of the timer increases. For maximum precision, you can obtain the timer value as an integer number of nanoseconds instead. You can improve accuracy by subtacting the integer counts first before converting to seconds. The actual resolution is system-dependent, but it should be able to accurately measure elapsed times of 1ms or less, substantially less on some systems.

Function Documentation

◆ realTimeInNs()

long long SimTK::realTimeInNs ( )
inline

Return current time on the high-resolution interval timer in nanoseconds, as a 64-bit integer count.

Generally it is more convenient to use realTime() which reports the interval time in seconds instead, but the nanosecond count is best for maximum accuracy and consistency.

Returns
Elapsed nanoseconds since some arbitrary time, as a 64 bit integer count.
See also
realTime(), nsToSec()

◆ realTime()

double SimTK::realTime ( )
inline

Return current time on the high-resolution interval timer in seconds.

For maximum precision, you can improve repeatability and accuracy somewhat by obtaining the interval times as integer counts using realTimeInNs().

Returns
Elapsed seconds since some arbitrary time, as a double precision floating point number.
See also
realTimeInNs()

◆ sleepInNs()

void SimTK::sleepInNs ( const long long &  ns)
inline

Sleep for the indicated number of nanoseconds, with the actual precision system dependent but intended to be the best achievable, hopefully less than 5ms in all cases.

However, when this wakes up you should not assume you reached the desired time; you could wake up a little earlier or a lot later. Alternatives to this are SimTK's sleepInSec() function, or the Posix nanosleep() and usleep() functions.

See also
sleepInSec()

◆ sleepInSec()

void SimTK::sleepInSec ( const double &  seconds)
inline

Sleep for the indicated number of seconds, with the actual precision system dependent but intended to be the best achievable, hopefully less than 5ms in all cases.

However, when this wakes up you should not assume you reached the desired time; you could wake up a little earlier or a lot later. Alternatives to this are the SimTK sleepInNs() function, or the Posix nanosleep() and usleep() functions.

See also
sleepInNs()