評論(0

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"


  &#039;


  &#039; Time timeGetTime


  &#039;


  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

上一篇[廠房]    下一篇 [現金]

相關評論

同義詞:暫無同義詞