timing VBA execution

J

JE McGimpsey

Charles Williams said:
How do you time VBA execution on the Mac with better resolution than 1
second?

I usually just use a MacScript call to the GetMilliSec OSAX.
 
C

Charles Williams

OK, I didnt understand several words in that.
How about some more clues for a Mac novice?

Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com
 
J

JE McGimpsey

Charles Williams said:
OK, I didnt understand several words in that.
How about some more clues for a Mac novice?

Sorry, Charles -

MacScript() is a VBA method that executes an Applescript script and
returns the result of the script.

OSAX is Open Scripting Architecture eXtension - also called a Scripting
Addition - compiled C/C++/etc code that can be called in Applescript.

Applescript is MacOS's natural-language scripting language.

So in VBA I wrap the code I'm timing with calls to an Applescript that
returns the system clock since startup in milliseconds:

Dim time1 as double, time2 as double
Dim i As Long

time1 = MacScript("GetMilliSec")
for i = 1 to 10000
'Do something
next i
time2 = MacScript("GetMilliSec")

MsgBox "Loop took " & time2 - time1 & " milliseconds."


the major problem with this method is that the function call obviously
takes time, so I usually use a null loop as a tare.

Also, OS X being a preemptive multitasking system, the results will vary
depending on how many other processes are running. When XL is the only
user app running and it's reniced to -20 the results are pretty
consistent, with an effective resolution of perhaps 10 milliseconds. If
you have other apps running the results can be wildly inconsistent, with
resolution no better than 250 milliseconds.

Since the PowerPC has a microsecond timer available, I've been telling
myself for years now that I'm going to write an API call to deliver
microsecond resolution to VBA. For some reason, I've always had more
important/urgent projects, though.
 
C

Charles Williams

many thanks for the explanations.

Not sure 10 milliseconds is enough resolution, I am using microseconds at
the moment.
I think I had better run some tests to find out what I really need ...

regards
Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com
 
C

Charles Williams

Looks like I currently need resolution of a tenth of a millisecond: actually
there is one place where I use 1/100 of a millisecond but I can scale that
back easily enough.

10 Millisecs is definitely not enough. And as Macs get faster the problem
gets worse.

So any ideas on how to write that API call to the powerPc microsecond timer?
(Someone must have done this already!)

regards
Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com
 

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