
Win32 API:QueryPerformanceFrequency说明
The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists.
QueryPerformanceFrequency函数接收高精度计时器的频率,如果(硬件支持)有(高精度计时器).
BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency // address of current frequency(当前频率地址)
);
Parameters
参数
- lpFrequency
- Pointer to a variable that the function sets, in counts per second, to the current performance-counter frequency. If the installed hardware does not support a high-resolution performance counter, this parameter can be to zero.
- 指向函数设定的变量,以次数/秒计算当前高精度计时器的频率.如果所安装的硬件不支持高精度计时器,这个参数将为0.
Return Values
返回值
If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
如果(所安装的)硬件支持高精度计时器,返回非0.
If the installed hardware does not support a high-resolution performance counter, the return value is zero.
如果(所安装的)硬件不支持高精度计时器,返回0.
QuickInfo
快速信息
Windows NT: Requires version 3.1 or later.需要3.1版本以上
Windows: Requires Windows 95 or later.需要Win95以上
Windows CE: Unsupported.不支持
Header: Declared in winbase.h.在winbase.h中声明
Import Library: Use kernel32.lib.使用kernel32.lib链接库
See Also
Timers Overview, Timer Functions, QueryPerformanceCounter
以下为函数说明(摘自互联网上)
queryperformancecounter()这个函数返回高精确度性能计数器的值,它可以以微秒为单位计时.但是queryperformancecounter()确切的精确计时的最小单位是与系统有关的,所以,必须要查询系统以得到queryperformancecounter()返回的嘀哒声的频率.queryperformancefrequency()提供了这个频率值,返回每秒嘀哒声的个数.计算确切的时间是从第一次调用queryperformancecounter()开始的假设得到的large_integer 为nstartcounter,过一段时间后再次调用该函数结束的,设得到nstopcounter.两者之差除以queryperformancefrequency()的频率就是开始到结束之间的秒数.由于计时函数本身要耗费很少的时间,要减去一个很少的时间开销.但一般都把这个开销忽略.公式如下:
nstopcounter-nstartcounter
elapsedtime=------------------------------------ - overhead
frequency
double time=(nstopcounter.quadpart-nstartcounter.quadpart)/frequency.quadpart.
: 科技

