请输入您要查询的百科知识:

 

词条 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

Declare Function QueryPerformanceCounter Lib "Kernel32" _

(X As Currency) As Boolean

Declare Function QueryPerformanceFrequency Lib "Kernel32" _

(X As Currency) As Boolean

Declare Function GetTickCount Lib "Kernel32" () As Long

Declare Function timeGetTime Lib "winmm.dll" () As Long

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

Debug.Print "Start Value: "; Format$(Ctr1, "0.0000")

Debug.Print "End Value: "; Format$(Ctr2, "0.0000")

QueryPerformanceFrequency Freq

Debug.Print "QueryPerformanceCounter minimum resolution: 1/" & _

Freq * 10000; " sec"

Debug.Print "API Overhead: "; (Ctr2 - Ctr1) / Freq; "seconds"

Else

Debug.Print "High-resolution counter not supported."

End If

'

' Time GetTickCount

'

Debug.Print

Loops = 0

Count1 = GetTickCount()

Do

Count2 = GetTickCount()

Loops = Loops + 1

Loop Until Count1 <> Count2

Debug.Print "GetTickCount minimum resolution: "; _

(Count2 - Count1); "ms"

Debug.Print "Took"; Loops; "loops"

'

' Time timeGetTime

'

Debug.Print

Loops = 0

Count1 = timeGetTime()

Do

Count2 = timeGetTime()

Loops = Loops + 1

Loop Until Count1 <> Count2

Debug.Print "timeGetTime minimum resolution: "; _

(Count2 - Count1); "ms"

Debug.Print "Took"; Loops; "loops"

End Sub

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/11/15 22:43:13