简体   繁体   English

在OSX上,Windows的QueryPerformanceCounter相当于什么?

[英]What's the equivalent of Windows' QueryPerformanceCounter on OSX?

我正在将一个库从Windows移植到* NIX(目前是OSX),现在有人可以使用什么功能代替Microsoft的QueryPerformanceCounter和QueryPerformanceFrequency?

On OSX mach_absolute_time and mach_timebase_info are 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

http://www.tin.org/bin/man.cgi?section=3&topic=clock_gettime (and the other functions mentioned there) - it's Posix! http://www.tin.org/bin/man.cgi?section=3&topic=clock_gettime (以及那里提到的其他功能) - 它是Posix! Will fall back to worse counters if HPET is not existent. 如果HPET不存在,将会回落到更糟糕的计数器。 (shouldn't be a problem though) (虽然不应该是一个问题)

http://en.wikipedia.org/wiki/High_Precision_Event_Timer http://en.wikipedia.org/wiki/High_Precision_Event_Timer

Resolution should be about +10Mhz. 分辨率应约为+ 10Mhz。

Try boost's ptime for portable high-resolution timing. 尝试使用boost的ptime进行便携式高分辨率计时。

Update (prompted, 2 years on, by Mark's comment below): 更新 (提示,2年后,Mark的评论如下):

These days I'd use a std::chrono::high_resolution_clock ; 这些天我用的是std::chrono::high_resolution_clock ; example . 例子

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

AudioConvertHostTimeToNanos(AudioGetCurrentHostTime())

Back in the day you had either uclock or you delved into assembler to read the RDTSC . 回到那一天,你或者你或者你已经钻研了汇编程序来阅读RDTSC

G. G。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM