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, you can use the QueryPerformanceFrequency function 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. 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.

高精度定时器

计数器(counter)是在编程过程中常用的术语,用来表示一个递增的变量。有一些系统包含一个高性能计数器,它提供一个高精度的消逝时间(elapsed times)。

如果在一个系统中存在高性能计数器,可以通过QueryPerformanceFrequency来获得计数频率,单位是每秒钟计数次数(cps)。这个值根据处理器的不同会有所不同。例如,在有些处理器上这个值可能等于处理器的时钟频率。

QueryPerformanceCounter函数取得当前高性能计数器的计数值。应用程序在一个代码段的前后调用这个函数来使用高性能计数器。例如,假设由QueryPerformanceFrequency函数得到高性能计数频率为50,000次每秒,如果应用程序在一个要计时的代码段前后调用QueryPerformanceCounter函数,得到的值假设分别是15003000,则这两个值说明了这段代码的执行时间是0.04秒(即2000次计数)。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值