I'm porting a library from Windows to *NIX (currently OSX), does anyone now what function can I use instead of Microsoft's QueryPerformanceCounter and QueryPerformanceFrequency?
+3
A:
http://www.tin.org/bin/man.cgi?section=3&topic=clock_gettime (and the other functions mentioned there) - it's Posix! Will fall back to worse counters if HPET is not existent. (shouldn't be a problem though)
http://en.wikipedia.org/wiki/High_Precision_Event_Timer
Resolution should be about +10Mhz.
Ronny
2009-01-21 10:10:03
A:
Back in the day you had either uclock or you delved into assembler to read the RDTSC.
G.
graham.reeds
2009-01-21 10:11:40
RDTSC is not reliable. Powersaving features, clock it down, up. Stop it ....
Ronny
2009-01-21 10:14:03
If you are using a high-resolution timer, the chances are you aren't going to be going into powersaving mode.
graham.reeds
2009-01-23 11:47:53
You may not be, but some other process may put the system into that mode. It depends on what kind of constraints your system has. For the general public its not guaranteed.
ApplePieIsGood
2009-01-23 16:12:11
It will also screw up if your process switches cpus, if I remember correctly ... we have done some evaluation using tsc + linux and the effect of powersaving features. Each core has its own tsc.
Ronny
2009-01-24 19:07:03
Recent AMD and Intel chips implement consistent RDTSC. Good enough for me.
Marius
2010-07-07 15:14:14
+1
A:
He asked about OS X. Use these APIs from CoreAudio:
AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())
Chris Reed
2009-12-12 04:33:17