How can I time the speed of a macro?
Wat do you get if you run this?
Dim nTime As Double
Dim i As Long
nTime = Timer
For i = 1 To 1000000
Next i
MsgBox Timer - nTime
--
__________________________________
HTH
Bob
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Bob,
Poor testing and bad luck on my part - I ran this twice:
MsgBox Format(Timer, "0.0000")
and each time it round tenths, so I jumped with both feet.
But I haven't seen any thing past hundreths....
Bernie
"Bob Phillips" wrote in message
...
I think it is a lot better resolution than 1/10th, have just got a result
of .015625
--
__________________________________
HTH
Bob
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
My apologies. Timer returns time to the nearest tenth of a second, so
the maximum error in two calls is one tenth of a second.
Bernie
"Bob Phillips" wrote in message
...
I am sorry, but my solution was Timer NOT Time. As help says ...
In Microsoft Windows the Timer function returns fractional portions of
a second. On the Macintosh, timer resolution is one second.
--
__________________________________
HTH
Bob
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Ryan,
The time function is not detailed enough - it only returns H:M:S, with
resolution of 1 second. That is why you need to use a High Resolution
Timer....
HTH,
Bernie
MS Excel MVP
"RyanH" wrote in message
...
I am getting Elapsed Time = 0 using the code below. The macro runs
pretty
fast. The code that I got from Bernie reads around .124560. Is the
time
function not detailed enough.
Sub TimeMacro()
Dim StartTime As Double
Dim EndTime As Double
StartTime = Time
Debug.Print "Start Time = " & StartTime
' my code here
EndTime = Time
Debug.Print "End Time = " & EndTime
Debug.Print "Elapsed Time = " & EndTime - StartTime
End Sub
--
Cheers,
Ryan
"Bob Phillips" wrote:
No, it is the number of seconds, although it will give decimal parts
of a
second as well.
--
__________________________________
HTH
Bob
"RyanH" wrote in message
...
Thanks for the reply Bob. How accurate is the Time Function? Is
it in
milliseconds? Because I can't seem to get this to work properly.
Do I
need
to multiply the Elapsed Time by 1000?
--
Cheers,
Ryan
"Bob Phillips" wrote:
Sub TimeMacro()
Dim StartTime As Double
Dim EndTime As Double
StartTime = Timer
Debug.Print "Start Time = " & StartTime
' my code here
EndTime = Timer
Debug.Print "End Time = " & EndTime
Debug.Print "Elapsed Time = " & EndTime - StartTime
End Sub
--
__________________________________
HTH
Bob
"RyanH" wrote in message
...
I would like to time the speed of a macro. I currently use this
code,
but
the StartTime and EndTime are the same, is that right? I don't
think
the
Time function is precise enough. Is there a accurate way of
timing the
speed
of a macro?
Sub TimeMacro()
Dim StartTime As Single
Dim EndTime As Single
StartTime = Time
Debug.Print "Start Time = " & StartTime
' my code here
EndTime = Time
Debug.Print "End Time = " & EndTime
Debug.Print "Elapsed Time = " & EndTime - StartTime
End Sub
--
Cheers,
Ryan
|