Measuring calculation time

S

Schizoid Man

Hello,

I have a workbook that takes about 20 minutes to calculate. Is there a quick
macro I can write that measures the actual time taken by the macro to
execute the calculations?

Thank you,
Schiz
 
J

Jim Cone

Something like...

Dim sngTime As Single
sngTime = Timer
'your code
MsgBox Format$(Timer - sngTime, "00.00")
--
Jim Cone
Portland, Oregon USA




"Schizoid Man" <[email protected]>
wrote in message
Hello,
I have a workbook that takes about 20 minutes to calculate. Is there a quick
macro I can write that measures the actual time taken by the macro to
execute the calculations?
Thank you,
Schiz
 
J

JoeU2004

Schizoid Man said:
I have a workbook that takes about 20 minutes to calculate.
Is there a quick macro I can write that measures the actual
time taken by the macro to execute the calculations?

The simplest method is to put calls to Timer() around the code to measured.
For example:

Sub doit1()
Dim st as Double, et as Double
st = Timer()
Application.Wait Now() + TimeSerial(0, 0, 2)
et = Timer()
Debug.Print "elapsed time: " & et - st
End Sub

That should work on Windows systems as well as the Mac, although the
precision of Timer() differs on the Mac. See the VB help page.

Alternatively:

Public Declare Function QueryPerformanceFrequency Lib _
"kernel32" (ByRef freq As Currency) As Boolean
Public Declare Function QueryPerformanceCounter Lib _
"kernel32" (ByRef cnt As Currency) As Boolean

Sub doit2()
Dim freq As Currency, sc As Currency, ec As Currency
x = QueryPerformanceFrequency(freq) 'constant
x = QueryPerformanceCounter(sc)
Application.Wait Now() + TimeSerial(0, 0, 2)
x = QueryPerformanceCounter(ec)
Debug.Print "elapsed time: " & (ec - sc) / freq
End Sub

That has the potential for measuring less than 1-msec precision.


----- original message -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top