unsigned int getMilliSeconds() {
struct timeb tb;
ftime(&tb);
return tb.time * 1000 + tb.millitm;
}
accurate timing in linux?
I looked into how timing can be done in linux/unix and I ran into this function:
Is there a more accurate way of achiving this?
According to the man page,
gettimeofday is normally the preferred function. It's accurate to 1us on most systems, which is typically enough for games.
Mark
Quote:
This function is obsolete. Don't use it. If the time in seconds suffices, time(2) can be used; gettimeofday(2) gives microseconds; clock_gettime(3) gives nanoseconds but is not yet widely available.
gettimeofday is normally the preferred function. It's accurate to 1us on most systems, which is typically enough for games.
Mark
like markr said, gettimeofday is the function for you.
like so:
like so:
double getAccurateTimeInSeconds(){ struct timeval tm; struct timezone tz; gettimeofday(&tm, &tz); return (double)(tm.tv_sec) + ((double)(tm.tv_usec) * 0.000001);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement