有人可以破译timeGetTime()或者QueryPerformanceCounter的/ QueryPerformanceFrequency的是否​​具有较低的开销或/和准确性? [英] Can someone decipher whether timeGetTime() or QueryPerformanceCounter/QueryPerformanceFrequency has lower overhead or/and accuracy?

查看:507
本文介绍了有人可以破译timeGetTime()或者QueryPerformanceCounter的/ QueryPerformanceFrequency的是否​​具有较低的开销或/和准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个想法是,现有的项目使用timeGetTime()(适用于Windows目标)相当频繁。

The idea is that an existing project uses timeGetTime() (for windows targets) quite frequently.

milliseconds = timeGetTime();

现在,这可以被替换为

double tmp = (double) lpPerformanceCount.QuadPart/ lpFrequency.QuadPart; 
milliseconds = rint(tmp * 1000);

与lpPerformanceCount.QuadPart和lpFrequency.QuadPart正在采取从使用到QueryPerformanceCounter的()和QueryPerformanceFrequency()的单个调用。

with lpPerformanceCount.QuadPart and lpFrequency.QuadPart being taken from the use of a single call to QueryPerformanceCounter() and QueryPerformanceFrequency().

我知道Windows的内部是一种巫术,但有人可以破译这两个是比较准确的和/或有更多的开销?

I know Windows' internals are kind of voodoo, but can someone decipher which of the two is more accurate or/and has more overheads?

我怀疑精度可能是相同的,但QueryPerformanceCounter的可能有少开销。但我没有确实的数据来支持它。

I suspect accuracy might be same but QueryPerformanceCounter might have less overheads. But I have no hard data to back it up.

当然,如果相反的是真的,我也不会感到惊讶。

Of course I wouldn't be surprised if the opposite is true.

如果费用有任何微小的方式,我会就是否有精度任何差别更感兴趣。

If overheads are tiny in any way I would be more interested on whether there's any difference in accuracy.

推荐答案

timeGetTime的()是可变的,精度基于上次使用的timeBeginPeriod。它不会比一毫秒更好。 QueryPerformanceCounter的是可变过,这取决于硬件支持。它永远不会超过一微秒差。

The accuracy of timeGetTime() is variable, based on the last used timeBeginPeriod. It will never be better than one millisecond. QueryPerformanceCounter is variable too, depending on hardware support. It will never be worse than about a microsecond.

他们都不具有显着的开销,QPC可能是有点重。不管是你显著是从你的问题还不是很清楚。我对此表示怀疑,但衡量。随着QPC。

Neither of them have notable overhead, QPC is probably a bit heavier. Whether that's significant to you is quite unclear from your question. I doubt it, but measure. With QPC.

这篇关于有人可以破译timeGetTime()或者QueryPerformanceCounter的/ QueryPerformanceFrequency的是否​​具有较低的开销或/和准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆