Advertisement

Timer on linux like QueryPerformanceFrequency( )

Started by September 03, 2002 05:43 PM
8 comments, last by shiverz 22 years, 5 months ago
Hi, I''m looking for a timing function for linux, similar to QueryPerformanceCounter( ) from Windows. It needs to give 8 bytes long precision. Those I found for Linux was only 4 bytes long (SDL_GetTicks) and the functions using time.h.
Look up gettimeofday (which goes down to nanoseconds) and/or ftime (which only goes to milliseconds, I think). If you''d looked in the "Everything Unix" forum before asked you''d have seen my answer to this from not too long ago.
Advertisement
Here is a quick example of the linux timers:

#include <sys/time.h>struct timeval startTime, endTime;struct timezone tz;gettimeofday(&startTime, &tz);gettimeofday(&endTime, &tz);startTime.tv_sec // number of seconds since some epochstartTime.tv_usec // number of microseconds since last second. 


Just subtract the startTime from the endTime and you can get at least sufficient precision.

SpiffGQ
Ok cool, i''ve calculated it .. it can hold about 106 years (maybe less .. it starts at 1970 or something ?) anyway its fine, but now how can I get the number of Ticks per seconds (like QueryPerformanceFrequency in windows ) ?

thanks for the help!
quote:
Original post by shiverz
but now how can I get the number of Ticks per seconds (like QueryPerformanceFrequency in windows ) ?

You don''t have to. The best method of retreiving the time is abstracted and the time is given in constant units from those functions.
Heheh, well, I have to, I want to calculate many things ... that Im doing currently with windows, like changing timer speed (like i can make it go twice as fast, going backward, and so on), getting fps, stop/starting timer, adding timers together, substracting timer.. and many things other wonderful things ... thats why i need ticks_per_sec .. but I think ive saw it someonewhere ... clock() ? maybe ?
Advertisement
just as a possible option, you could use ASM to query the clock counter, and then work out the processor frequency as your clocks per second.
Ehh that would be nice ... I''ll google it =)
But I'm sure sys/time.h would provide clock ticks per second ...

[edited by - shiverz on September 3, 2002 10:52:03 PM]
There''s ASM code to read the Time Stamp Counter under gcc here. It''s right near the bottom of the thread.

Enigma

This topic is closed to new replies.

Advertisement