Win32中的时差(以秒为单位) [英] Time difference in seconds in Win32

查看:88
本文介绍了Win32中的时差(以秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI 我需要在win32中获得以秒为单位的时差.

例如:我有一个功能.我必须以秒为单位获取功能执行所需的时间.我尝试使用GetTickCount(),但是那无济于事.

HI I need to get the time difference in seconds in win32 .

Eg: I have a function . i have to get the time in sec the function has taken to execute . I tried using GetTickCount() , but thats not helping out.

推荐答案

您没有解释为什么GetTickCount()对您不起作用.如果在执行函数之前调用GetTickCount(),然后在执行函数之后再次调用,则从结束值中减去起始值将返回经过的时间(以毫秒为单位).

真的很琐碎:
You did not explain why GetTickCount() is not working for you. If you call GetTickCount() before you execute your function and again after, subtracting the start value from the end value returns the elapsed time in ms.

It is really quite trivial:
DWORD startCount = GetTickCount();

// Run your funciton here.

DWORD endCount = GetTickCount();

DWORD timeSpan = end - start;



也许您的问题是结果不够准确-如果您的函数执行得足够快,这是很常见的.在这种情况下,您可以尝试使用QueryPerformanceCounter().使用起来稍微复杂一些,但精度更高.

如果您使用Google QueryPerformanceCounter(),则会发现很多匹配项,例如
用于更精确的时间间隔测量的C ++类 [ ^ ]
这是MSDN文章 [此处是有关StackOverflow的讨论 [



Perhaps your problem is that the result is not accurate enough - this is quite common if your function executes fast enough. In that case, you can try out QueryPerformanceCounter(). It is a little more complex to work with but has a much higher accuracy.

If you Google QueryPerformanceCounter() you will find lots of hits, such as
A C++ class for more precise time interval measurement[^]
Here is an MSDN article[^]
Here is a discussion on StackOverflow[^]


Soren Madsen


这篇关于Win32中的时差(以秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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