views:

2206

answers:

4

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
A: 

Back in the day you had either uclock or you delved into assembler to read the RDTSC.

G.

graham.reeds
RDTSC is not reliable. Powersaving features, clock it down, up. Stop it ....
Ronny
If you are using a high-resolution timer, the chances are you aren't going to be going into powersaving mode.
graham.reeds
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
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
Recent AMD and Intel chips implement consistent RDTSC. Good enough for me.
Marius
A: 

Try boost's ptime for portable high-resolution timing.

timday
+1  A: 

He asked about OS X. Use these APIs from CoreAudio:

AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())
Chris Reed