Go to the first, previous, next, last section, table of contents.


uclock

Syntax

#include <time.h>

uclock_t uclock(void);

Description

This function returns the number of uclock ticks since an arbitrary time, actually, since the first call to uclock, which itself returns zero. The number of tics per second is UCLOCKS_PER_SEC.

uclock is provided for very high-resulution timing. It is currently accurate to better than 1 microsecond (actually about 840 nanoseconds). You cannot time across two midnights with this implementation, giving a maximum useful period of 48 hours and an effective limit of 24 hours. Casting to a 32-bit integer limits its usefulness to about an hour before 32 bits will wrap.

Note that printf cannot print a value of type uclock_t, even though it is an integer value, because it is a 64-bit integer.

Also note that uclock reprograms the interval timer in your PC to act as a rate generator rather than a square wave generator. I've had no problems running in this mode all the time, but if you notice strange things happening with the clock (losing time) after using uclock, check to see if this is the cause of the problem.

Return Value

The number of tics.

Portability

not ANSI, not POSIX

Example

printf("%d seconds have elapsed\n", (int)(uclock()/UCLOCKS_PER_SEC));


Go to the first, previous, next, last section, table of contents.