High-Resolution Timer

High-Resolution Timer

A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.

 

以上来自MSDN.

 

 

 

       计数器是程序设计中增量的一个通用术语。有些系统提供高精度的计数器。

 

       若系统提供高精度计数器,函数QueryPerformanceFrequency()可以取得频率:次/秒。这个值取决于CPU。如在一些操作系统上,这个值可能是CPU的主频。

 

       函数QueryPerformanceCounter()取得CPU运行到现在TickCPU振荡了多少次)了多少次。通过在要计时的程序之前和之后分别调用此函数,可以高精度的计时。例如:假设函数QueryPerformanceFrequency()表明振荡频率为50,000/秒,若一个程序在要计时的程序段之前和之后立即调用函数QueryPerformanceCounter(),计数器的值可能分别是1500, 3500,这就表明那段要计数的程序段执行了0.04秒(2000次)。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值