Browse DevX
Sign up for e-mail newsletters from DevX


Using High-resolution Timers

For multimedia streaming, games, and profiling, Standard C++'s time-meausurement facilities are limited. For high-resolution timers, look to the POSIX libraries

tandard C++ offers a rather limited number of functions for accurate time measurement: clock() gives you a granularity of up to a thousandth of a second at best, and difftime() compares two different time() readings. However, when it comes to multimedia streaming, games and profiling, you want higher resolution timers. The following sections present POSIX high-resolution timers. These timers are available on POSIX systems and to some extent, on Windows, too.

You need high-resolution timers that measure microseconds and even nanoseconds. However, the standard <ctime> facilities are a long way from providing that kind of capability.

When the ISO C++ standard doesn't provide the answers, use another portable and reliable standard library—POSIX.

Thanks for your registration, follow us on our social networks to keep up-to-date