Advertisement

High Resolution Unix timer

Started by January 13, 2004 08:44 AM
9 comments, last by NuffSaid 20 years, 5 months ago
Is there a function to access a high resolution timer on the Unix platform? I''m looking for something similar to the Win32 QueryperformanceCounter.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
I used gettimeofday() for my engine. It has microsecond resolution (the exact degree I am not sure).

I am not familar with the QueryperfomanceCounter so I am not sure f this will meet your needs.
Advertisement
As I recall, there was some kernel hacking related to 2.6, rdtsc, and nanosecond resolution if that''s not enough.

I forget which syscall it was for though, maybe it was gettimeofday
SDL has millisecond (ie 1/1000) accuracy to some degree.
My stuff.Shameless promotion: FreePop: The GPL god-sim.
Looks like SDL seems to be the best option so far. Is there really no built in high resolution timer in Unix? How do you guys write games then? Do all of you use gettimeofday()?

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
quote: Original post by NuffSaid
Looks like SDL seems to be the best option so far. Is there really no built in high resolution timer in Unix? How do you guys write games then? Do all of you use gettimeofday()?

How is gettimeofday not a built-in high resolution timer? It's what SDL uses if I recall correctly. You can also use clock_gettime for another POSIX option (they're both "new" POSIX from 2001, gettimeofday is also part of BSD 4.3 and has been supported under Linux for quite a while).

[edited by - Null and Void on January 14, 2004 3:55:27 PM]
Advertisement
Indeed last I looked SDL_GetTime() does use gettimeofday() internally. Always struck me odd that that we had to jump though hoops for Windows''s QueryPerformanceCounter() functions. ... I probably just don''t know enough details is all
Ah well, gettimeofday() it is then.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Quake II uses gettimeofday(), too. In my program, it also works nicely, but I don''t need a really precise timer.

Anyways, you can still hack your way down the assembly lane and ask the CPU... thats the rtdsc thingie mentioned before.

QueryPerformanceCounter resolution depends on the device you use. my 1 Ghz Intel has 1/1.000.000 s resolution (microsecond), my 2,5+ Athlon has just about 1/300.000 s which is less than a third...

I don''t believe nanoseconds is realistical timing because in a nanosecond, light only travels 30 cm...
I just looked up a C# implementation of QueryPerformanceCounter() (it somewhare on the web, available under the shared source license)

and it uses gettimeofday().

edit:spell

[edited by - C-Junkie on January 22, 2004 3:35:51 PM]

This topic is closed to new replies.

Advertisement