C++ OSX 上的 Windows QueryPerformanceCounter 相当于什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/464618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the equivalent of Windows' QueryPerformanceCounter on OSX?
提问by Paolo
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?
我正在将一个库从 Windows 移植到 *NIX(当前为 OSX),现在有没有人可以使用什么函数来代替 Microsoft 的 QueryPerformanceCounter 和 QueryPerformanceFrequency?
采纳答案by Ronny Brendel
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://www.tin.org/bin/man.cgi?section=3&topic=clock_gettime(以及那里提到的其他功能) - 它是 Posix!如果 HPET 不存在,将退回到更差的计数器。(虽然应该不是问题)
http://en.wikipedia.org/wiki/High_Precision_Event_Timer
http://en.wikipedia.org/wiki/High_Precision_Event_Timer
Resolution should be about +10Mhz.
分辨率应该在+10Mhz左右。
回答by Justicle
On OSX mach_absolute_time
and mach_timebase_info
are the best equivalents to Win32 QueryPerformance* functions.
在 OSX 上mach_absolute_time
,mach_timebase_info
是 Win32 QueryPerformance* 函数的最佳等效项。
See http://developer.apple.com/library/mac/#qa/qa1398/_index.html
见http://developer.apple.com/library/mac/#qa/qa1398/_index.html
回答by timday
回答by Chris Reed
He asked about OS X. Use these APIs from CoreAudio:
他询问了 OS X。使用 CoreAudio 的这些 API:
AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())