I was wondering if someone knows if there is some type of VB Timer that will time how long your code runs for. I ask this because i am looking for a way to optimize the speed of my code.
I was wondering if someone knows if there is some type of VB Timer that will time how long your code runs for. I ask this because i am looking for a way to optimize the speed of my code.
Hi,
To measure time in seconds (and parts of seconds) you can use Timer function. This function returns seconds from Midnight.
Hope this helps.Code:Sub TestTime() Dim sStartTime As Single Dim sEndTime As Single 'Stores start time sStartTime = Timer 'Place your code here 'Stores end time sEndTime = Timer 'Show execution time Debug.Print "Execution time in seconds: ", sEndTime - sStartTime End Sub
Regards,
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.
Hi,
I have used the method Sweet Dreams suggests very effectively in the past to do exactly what you want to do.
Regards,
There is also the TimeGetTime() API function which is very accurate
The code I have used in the past to do this is:
Code:Private Declare Function GetTickCount Lib "kernel32.dll"() As Long Private Sub Time_Code() Dim t as 'Long t = GetTickCount 'Put code to be timed here MsgBox "Code took " & GetTickCount - t & _ " milliseconds to run.", vbInformation, "Time Taken" End Sub