What's the equivalent of Windows' QueryPerformanceCounter on OSX? What's the equivalent of Windows' QueryPerformanceCounter on OSX? unix unix

What's the equivalent of Windows' QueryPerformanceCounter on OSX?


On OSX mach_absolute_time and mach_timebase_info are the best equivalents to Win32 QueryPerformance* functions.

See http://developer.apple.com/library/mac/#qa/qa1398/_index.html


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.


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

Update (prompted, 2 years on, by Mark's comment below):

These days I'd use a std::chrono::high_resolution_clock ; example.