Timer on linux like QueryPerformanceFrequency( )
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.
September 03, 2002 06:05 PM
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.
Here is a quick example of the linux timers:
Just subtract the startTime from the endTime and you can get at least sufficient precision.
#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!
thanks for the help!
September 03, 2002 09:15 PM
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 ?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement