2015-01-20 204 views
1

我已经完成了一个图像加密函数的编写,并且我想计算函数的时间和cpu执行。此代码是用Visual Basic 6.0编写的。你有准确性代码来计算VB 6.0中这个函数的时间和CPU支出吗?在VB 6.0中以毫秒计算执行时间

+0

很难告诉你问什么,但既然你没有发布任何代码,它看起来像你要求有人为你写一个计时器功能。以下是一个示例链接:http://www.windowsdevcenter.com/pub/a/windows/2005/03/01/VB_timer.html。或者,如果您有代码并需要帮助,请用您尝试过的方式更新您的问题,以及问题的哪一部分是问题。 – jac 2015-01-21 00:25:28

+0

如果我没有记错,TimeGetTime是非常准确的,从winmm.dll。 https://msdn.microsoft.com/en-us/library/windows/desktop/dd757629%28v=vs.85%29.aspx – xpda 2015-01-22 05:04:27

回答

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测量不够准确