获取时间计数函数

发布于 2024-09-13 22:38:52 字数 207 浏览 4 评论 0 原文

我有一个关于 GetTickCount 函数的问题, 我在代码中对该函数进行了两次调用,它们之间有多个命令,并且两次调用中的函数返回相同的计数。 即

var1 = GetTickCount();
code
:
:
var2 = GetTickCount();

var1 和 var2 具有相同的值。

有人可以帮忙吗?

I have a question regarding GetTickCount function,
I have two calls to this function in my code with several commands between them and the function in both calls returns same count.
i.e.

var1 = GetTickCount();
code
:
:
var2 = GetTickCount();

var1 and var2 has same values in it.

can someone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

秉烛思 2024-09-20 22:38:52

假设这是 Windows GetTickCount 调用,这完全是合理的:

GetTickCount的分辨率
功能受限于分辨率
系统定时器,即
通常在 10 范围内
毫秒到 16 毫秒。

请注意,它一开始只测量毫秒 - 如今您可以在一毫秒内完成很多事情。

文档继续说:

如果您需要更高分辨率的计时器,
使用多媒体计时器
高分辨率计时器

也许QueryPerformanceCounter 会更合适吗?

Assuming this is the Windows GetTickCount call, that's entirely reasonable:

The resolution of the GetTickCount
function is limited to the resolution
of the system timer, which is
typically in the range of 10
milliseconds to 16 milliseconds.

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:

If you need a higher resolution timer,
use a multimedia timer or a
high-resolution timer.

Perhaps QueryPerformanceCounter would be more appropriate?

单挑你×的.吻 2024-09-20 22:38:52

如果您指的是 Windows API 调用,请阅读
我猜您正在尝试安排一个较短的时间间隔,因此本段是相关的。您是否正在安排比该间隔更短的时间?如果是这样,也许可以看看 QueryPerformanceCounter 。

GetTickCount的分辨率
功能受限于分辨率
系统定时器,即
通常在 10 范围内
毫秒到 16 毫秒。这
GetTickCount 的分辨率
功能不受
作出的调整
GetSystemTimeAdjustment函数。

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.

The resolution of the GetTickCount
function is limited to the resolution
of the system timer, which is
typically in the range of 10
milliseconds to 16 milliseconds. The
resolution of the GetTickCount
function is not affected by
adjustments made by the
GetSystemTimeAdjustment function.

北凤男飞 2024-09-20 22:38:52

如果您采用 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

吾家有女初长成 2024-09-20 22:38:52

来自 MSDN

GetTickCount的分辨率
功能受限于分辨率
系统定时器,即
通常在 10 范围内
毫秒到 16 毫秒。这
GetTickCount 的分辨率
功能不受
作出的调整
GetSystemTimeAdjustment函数。

经过的时间存储为 DWORD
价值。因此,时间将结束
如果系统运行则接近于零
连续49.7天。为了避免
这个问题,使用GetTickCount64
功能。否则,请检查是否有
比较时的溢出条件
次。

如果您需要更高分辨率的计时器,
使用多媒体定时器或
高分辨率计时器。

From MSDN

The resolution of the GetTickCount
function is limited to the resolution
of the system timer, which is
typically in the range of 10
milliseconds to 16 milliseconds. The
resolution of the GetTickCount
function is not affected by
adjustments made by the
GetSystemTimeAdjustment function.

The elapsed time is stored as a DWORD
value. Therefore, the time will wrap
around to zero if the system is run
continuously for 49.7 days. To avoid
this problem, use the GetTickCount64
function. Otherwise, check for an
overflow condition when comparing
times.

If you need a higher resolution timer,
use a multimedia timer or a
high-resolution timer.

半衾梦 2024-09-20 22:38:52

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文