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函数,得到的值假设分别是1500和3000,则这两个值说明了这段代码的执行时间是0.04秒(即2000次计数)。