C GetTickCount(windows函数)到时间(纳秒)
我正在测试同事提供的一段代码,我需要测量一个例程的执行时间,而不是执行(线程)上下文切换。
测量时间的最佳选择是什么?我知道可以使用高分辨率计时器,
QueryPerformanceCounter
QueryPerformanceFrequency
但我如何使用该计时器将其转换为毫秒或纳秒?
I'm testing one code provided from my colleague and I need to measure the time of execution of one routine than performs a context switch (of threads).
What's the best choice to measure the time? I know that is available High Resolution Timers like,
QueryPerformanceCounter
QueryPerformanceFrequency
but how can I translate using that timers to miliseconds or nanoseconds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
d 是以秒为单位的时间间隔。
d is time interval in seconds.
由于我正在执行的操作约为 500 纳秒,并且计时器没有精度,所以我所做的是,
我使用 GetTickCount() 保存了实际时间 - (使用 ~ 12milis 的精度)并执行路线 N_TIMES (例程执行的次数)比保留,直到我在控制台上按下某些内容。
再次计算时间,将差值除以N_TIMES,类似这样:
int static counter;
:)
As the operation than i am executing is in order of 500 nanos, and the timers doens't have precision, what i made was,
i saved actual time with GetTickCount() - (Uses precision of ~ 12milis) and performs the execution of a route N_TIMES (Number of times than routine executed) than remains until i press something on console.
Calculate the time again, and make the difference dividing by N_TIMES, something like that:
int static counter;
:)