I'm trying to measure how long it takes to run code. So I added the stopwatch object in the code, started it, and debug printed the elapsed time. The elapsed time is incorrect.
Can somebody tell me what I did wrong here?
During each pass in the For-Loop, the date stamp prints the wrong time...seems to be lagging. What is causing this?
Can somebody tell me what I did wrong here?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Long, sw As New System.Diagnostics.Stopwatch
sw.Start()
For x = 1 To 5000
Debug.Print(Now & vbTab & x & vbTab & sw.Elapsed.TotalSeconds.ToString("0.000"))
Next
Debug.Print("elapsed time " & sw.Elapsed.TotalSeconds.ToString("0.000"))
End Sub
During each pass in the For-Loop, the date stamp prints the wrong time...seems to be lagging. What is causing this?