在VB 6.0中计算执行时间(以毫秒为单位)

时间:2015-01-20 21:38:34

标签: math image-processing vb6

我已经完成了图像加密功能的编写,我想计算函数的时间和CPU执行。此代码是用Visual Basic 6.0编写的。您是否有准确度代码来计算VB 6.0中此函数的时间和CPU支出?

1 个答案:

答案 0 :(得分:0)

您可以使用GetTickCount()Api

Option Explicit

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
  YourFunction
End Sub

Private Function YourFunction() As Long
  Dim lngTime As Long
  Dim lngIndex As Long
  'record start
  lngTime = GetTickCount
  'do your thing
  For lngIndex = 1 To 10000
    Caption = CStr(lngIndex)
  Next lngIndex
  'record passed time
  lngTime = GetTickCount - lngTime
  Print "execution took " & CStr(lngTime); " ms"
End Function

注意虽然cpu定时器的分辨率对于ms测量来说不够准确