获取时间计数函数
我有一个关于 GetTickCount 函数的问题, 我在代码中对该函数进行了两次调用,它们之间有多个命令,并且两次调用中的函数返回相同的计数。 即
var1 = GetTickCount();
code
:
:
var2 = GetTickCount();
var1 和 var2 具有相同的值。
有人可以帮忙吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设这是 Windows GetTickCount 调用,这完全是合理的:
请注意,它一开始只测量毫秒 - 如今您可以在一毫秒内完成很多事情。
文档继续说:
也许
QueryPerformanceCounter
会更合适吗?Assuming this is the Windows GetTickCount call, that's entirely reasonable:
Note that it's only measuring milliseconds to start with - and you can do an awful lot in a millisecond these days.
The docs go on to say:
Perhaps
QueryPerformanceCounter
would be more appropriate?如果您指的是 Windows API 调用,请阅读此。
我猜您正在尝试安排一个较短的时间间隔,因此本段是相关的。您是否正在安排比该间隔更短的时间?如果是这样,也许可以看看 QueryPerformanceCounter 。
If you are referring to the Windows API call then read this.
I would guess that you are trying to time a short interval so this paragraph is relevant. Are you timing something shorter than that interval? If so look into QueryPerformanceCounter instead perhaps.
如果您采用 QueryPerformanceCounter 路线,则需要注意硬件相关怪异。已经有一段时间了,不知道这样的事情是否还会发生。
您可能还想看看在此链接,因为它有一个很好的示例应用程序,可以比较 QueryPerformanceCounter、GetTickCount 和 TimeGetTime
If you go the QueryPerformanceCounter route you need to watch out for hardware dependent wierdness. Its been awhile so I don't know if this kinda stuff still happens.
You might also want to take a look at this link since it has a nice sample app which compares QueryPerformanceCounter, GetTickCount and TimeGetTime
来自 MSDN
From MSDN
GetTickCount 的分辨率为一毫秒(实际上,为几毫秒)。您在其间调用的函数所花费的时间很可能大大少于 1 毫秒。
GetTickCount has a resolution of one millisecond (in practice, it's several milliseconds). It's highly likely that the functions you're calling in between are taking considerably less than 1 millisecond.