QueryPerformanceCounter
为一个指针变量用于函数传值提供高分辨率计时器
QueryPerformanceCounter是为一个指针变量用于函数传值,提供高分辨率计时器。
简介
The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter, if one exists.
BOOL QueryPerformanceCounter(
LARGE_INTEGER *lpPerformanceCount // pointer to counter value
);
Parameters
lpPerformanceCount
Pointer to a variable that the function sets, in counts, to the current performance-counter value. If the installed hardware does not support a high-resolution performance counter, this parameter can be to zero.
Return Values
If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
If the installed hardware does not support a high-resolution performance counter, the return value is zero.
中文译文
函数QueryPerformanceCounter用于得到高精度计时器的值(如果存在这样的计时器)
BOOL QueryPerformanceCounter(LARGE_INTEGER *ipPerformanceCount);//参数指向计数器的值
参数LARGE_INTEGER *ipProformanceCount
为一个指针变量用于函数传值,即指向现时计数器的值.如果安装的硬件不支持高精度计时器,该参数将返回0,
关于返回值:
如果安装的硬件支持高精度计时器,函数将返回非0值.
如果安装的硬件不支持高精度计时器,函数将返回0.
)
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
计时代码以查明性能瓶颈, 时要使用系统有以提供高分辨率计时器。 下例介绍如何使用 QueryPerformanceCounter 函数以应用程序代码。
输入下列代码插入模块。 如果类、, 窗体或报表模块, 中输入它使声明 Private。
Option Explicit
(X As Currency) As Boolean
(X As Currency) As Boolean
Declare Function timeGetTime
Sub Test_Timers()
Dim Ctr1 As Currency, Ctr2 As Currency, Freq As Currency
Dim Count1 As Long, Count2 As Long, Loops As Long
'
' Time QueryPerformanceCounter
'
If QueryPerformanceCounter(Ctr1) Then
QueryPerformanceCounter Ctr2
QueryPerformanceFrequency Freq
Else
End If
'
' Time GetTickCount
'
Debug.Print
Loops = 0
Count1 = GetTickCount()
Do
Count2 = GetTickCount()
Loops = Loops + 1
Loop Until Count1 <> Count2
'
'
Debug.Print
Loops = 0
Count1 = timeGetTime()
Do
Count2 = timeGetTime()
Loops = Loops + 1
Loop Until Count1<>Count2
End Sub
参考资料
最新修订时间:2024-06-23 00:48
目录
概述
简介
参考资料