Hi
I want to count time to execute the following loop.
Suppose
For i=1 To 5000
...........
.........
next i
would you please let me know how could I use the timer to count that time.
Thanks a lot.
Razzaqul
Printable View
Hi
I want to count time to execute the following loop.
Suppose
For i=1 To 5000
...........
.........
next i
would you please let me know how could I use the timer to count that time.
Thanks a lot.
Razzaqul
are you talking about measuring the time it takes to execute the loop?
if so, don't use a timer - do something like this:that's good to about 15 milliseconds - if you want more accurate results then you have to use more code (& different API)VB Code:
Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Command1_Click() Dim I As Long, lTimer As Long lTimer = GetTickCount For I = 1 To 5000 ' Your Code Next I Debug.Print "Time Taken: " & GetTickCount - lTimer End Sub
Would it be appropriate to use something like this?
VB Code:
Private Sub Command1_Click() Dim i As Integer Dim StartTime, EndTime, ElapsedTime As Single StartTime = Timer For i = 1 To 5000 'your code here Next i EndTime = Timer ElapsedTime = EndTime - StartTime Debug.Print ElapsedTime End Sub
ElapsedTime should hold the time to the millisecond that the procedure took, yes?
The timer has a granularity of 1ms (can be set to the nearest ms), but its accuracy is about 50ms +/- any routines that keep it from getting clock ticks - so GetTickCount is 3 times as accurate if nothing else is running, and better if something is.