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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:29:49  来源:igfitidea点击:

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

c++cwindowsunixporting

提问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_timeand mach_timebase_infoare the best equivalents to Win32 QueryPerformance* functions.

在 OSX 上mach_absolute_timemach_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

Try boost's ptimefor portable high-resolution timing.

尝试使用 boost 的ptime进行便携式高分辨率计时。

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

更新(提示,2 年后,马克在下面的评论):

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

这些天我会使用std::chrono::high_resolution_clock; 例子

回答by Chris Reed

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

他询问了 OS X。使用 CoreAudio 的这些 API:

AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())

回答by graham.reeds

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

早在您拥有 uclock 或深入研究汇编程序以读取RDTSC 的那一天。

G.

G。