Another goofy programmer question, what's the fastest and most accurate way of getting the

current time in milisecs within a program? I've been calling gettimeofday, but was wondering

if there's any better/faster way of doing it?

As far as I know gettimeofday() is the best way. Remember the structure it fills contains fields for seconds and microseconds, so if you want milliseconds you're goina have to do some math (and probably use a 64bit type). There is also ftime(), but it is deprecated.

What do you need it for? If you want to benchmark some algorithm or something I think you can use clock() (run it once before, once after, subtract and then divide by
CLOCKS_PER_SEC * 1000)

If you want to run some code after a specified amount of time then you can use alarm() or
setitimer().

Some boxes also have /dev/rtc which you can be configured (by ioctl()'s) to send data from 1 time a second all the way up to 2^13 times per second. (2^6 times per seconds is the max for non-root users).
--Ray

Reply via email to