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

删除回忆录丶 提交于 2019-11-27 05:40:01

问题


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?


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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

AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())



回答5:


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

G.



来源:https://stackoverflow.com/questions/464618/whats-the-equivalent-of-windows-queryperformancecounter-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!