VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



speedcheck calculates a functions runtime in ms (4 code-optimization)

by Max Christian Pohle (9 Submissions)
Category: Miscellaneous
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

Just one line of code is needed to test a functions speed -> With this class-module.
It creates an object which is automatically terminated together with the function you check and it uses debug.print to let you know how long your pc had been busy (in ms) with that function.
Sure you can save the value of timer() and read it before your function reaches exit/end function, but its harder to remove this before you release your app... So try this!

Assumes
Dim A as New <Object> is slower than Dim A as <Object>: Set A = New <Object>
API Declarations
'Create a new Class-Module for this
'and call it "SpeedCheck":

Option Explicit
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Private StartPoint As Long
Public Property Get CurRunTime() As Long
RunTime = GetTickCount - StartPoint
End Property
Private Sub Class_Initialize()
StartPoint = GetTickCount
End Sub
Private Sub Class_Terminate()
Debug.Print "- - - - - Your function needed: " & GetTickCount - StartPoint & " ms"
End Sub

Rate speedcheck calculates a functions runtime in ms (4 code-optimization)

'This is just an example to use it...
'Its as easy as possible- 
'therefor I do not use option explicit here
'and I work with a slow variant-datatype :-)
Private Sub Form_Load()
  Dim A As SpeedCheck: Set A = New SpeedCheck
  
  For I = 0 To 1000
    Debug.Print "Debug-Print is very slow!"
  Next I
End Sub

Download this snippet    Add to My Saved Code

speedcheck calculates a functions runtime in ms (4 code-optimization) Comments

No comments have been posted about speedcheck calculates a functions runtime in ms (4 code-optimization). Why not be the first to post a comment about speedcheck calculates a functions runtime in ms (4 code-optimization).

Post your comment

Subject:
Message:
0/1000 characters