How to measure how much time it takes to execute a function or a block of code or event a statement
Posted on August 10, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 'System & API - How to measure how much time it takes to execute a function or a block of code or event a statement 'The following snippet demonstrates the use of the GetTickCount API function. 'The return value is the number of milliseconds that have elapsed since the 'operating system was booted. 'This function is ideal for measuring how much time it takes to execute a 'function or a block of code or event a statement. Private Declare Function GetTickCount Lib "kernel32" () As Long 'This code will display the amount of time elapsed in seconds to execute a loop '100 times. Place this code in a command button's click event. Private Sub cmdElapsedTime_Click() Dim I As Long Dim LUBound As Long Dim Start As Long Dim LEnd As Long 'Set upper bound of loop. LUBound = 100 'Get starting tick value. Start = GetTickCount 'Execute loop. For I = 1 To LUBound Next I 'Get ending tick value. LEnd = GetTickCount 'Display elapsed time. MsgBox "Time elapsed = " & CStr((LEnd - Start) / 1000) & " seconds." End Sub |