Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro performance checker 2

Status
Not open for further replies.

eHanSolo

Technical User
May 24, 2004
260
GB
Hi ppl,

Just wondering... can anyone help with this:

Can a macro be written to specifically test how long it takes for a certain macro(any) to be run. Ideally, i'd like to be able to compare any changes i make to an existing macro so I know that the changes i've made to an existing macro has actually helped to improve the efficiency... and vice versa.

In fact, it doesn't have to be a macro... i suppose i could sit there with a stop watch...but it's not ideal!

many thanks!!!
 
Why not put a timer at the start and end of the macro to work out how long it has taken to run.
Code:
z = TIME
Call Macro1
y = TIME
x = y-z
mes$ = MsgBox("This macro took " & x & " to complete")
 
You might want to format the elapsed time
Code:
mes$ = MsgBox("This macro took " & Format(x, "[h]:mm:ss") & " to complete")

Skip,

[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue]
 
Is accuracy to the hundreths of a second sufficient for your purposes? If so, then using the Time function is just fine. However, if you need greater precision in your timing, you may want to look at the GetTickCount API (~55 millisecond precision), or the QueryPerformanceCounter, which gives precision into microseconds, depdending on your machine.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
wow... don't really need it cajun...but thanks all the same for the extra info!!!

Cheers,

E
 
Hi

CajunCenturion, how would you make the code display the hundreths of a second?

Jens Busse
Workflow Consultant
CCI Europe A/S
 
My mistake, it is not the Time function, but the Timer function that you need to use. The Timer function returns the number of seconds, to hundreths of seconds precision since midnight.

The Time function gives you seconds precision
The Timer function gives you hundreths of seconds precision.
The GetTickCount is about 55 millisecond precision
The QueryPerformanceCounter is into microsecond precision.


Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top