Go to the first, previous, next, last section, table of contents.
#include <time.h> uclock_t uclock(void);
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
(declared
in the `time.h' header file.
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
will only print a value of type uclock_t
correctly if you use format specifiers for long long
data, such
as %Ld
or %lld
, because uclock_t
is a 64-bit integer.
See section printf.
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.
Windows 3.X doesn't allow to reprogram the timer, so the values returned
by uclock
there are incorrect. DOS and Windows 9X don't have
this problem.
The number of tics.
not ANSI, not POSIX
printf("%Ld ticks have elapsed\n", (long long)(uclock())); printf("%f second have elapsed\n", ((double)uclock()/UCLOCKS_PER_SEC));
Go to the first, previous, next, last section, table of contents.