当前位置:首页 科普知识 QueryPerformanceCounter

QueryPerformanceCounter

发布时间:2023-09-14 19:58:44

QueryPerformanceCounter是为一个指针变量用于函数传值,提供高分辨率计时器。

QueryPerformanceCounter介绍

QueryPerformanceCounter是为一个指针变量用于函数传值,提供高分辨率计时器。

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中文译文

函数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

QueryPerformanceCounter

'

' 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

QueryPerformanceCounter

Debug.Print "timeGetTime minimum resolution: "; _

(Count2 - Count1); "ms"

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

End Sub

温馨提示:
本文【QueryPerformanceCounter】由作者 爱百科 转载提供。 该文观点仅代表作者本人, 自学教育网 信息发布平台,仅提供信息存储空间服务, 若存在侵权问题,请及时联系管理员或作者进行删除。
(c)2008-2025 自学教育网 All Rights Reserved 汕头市灵创科技有限公司
粤ICP备2024240640号-6