VBA - Timing A Block Of Lines

A

ajocius

Group,
I'm trying to find out how long blocks of code take to execute in
order to balance my program. Below is a sample of programming I'm
using to attempt this. I doesn't seem to work. Any help for a novice
would be awesome.

Dim StartTime As Long
Dim EndTime As Long
Dim TotalTime As Long
...
...
...
...
...
StartTime = Now()
...
...
...
EndTime = Now()
TotalTime = EndTime - StartTime





Tony
 
B

Bill Martin

ajocius said:
Group,
I'm trying to find out how long blocks of code take to execute in
order to balance my program. Below is a sample of programming I'm
using to attempt this. I doesn't seem to work. Any help for a novice
would be awesome.

Dim StartTime As Long
Dim EndTime As Long
Dim TotalTime As Long
..
..
..
..
..
StartTime = Now()
..
..
..
EndTime = Now()
TotalTime = EndTime - StartTime





Tony
------------------------

If you're trying to time a few lines of code, I don't know how you can do it
directly given the vagaries of applications interacting with the operating
system. Even if you could do it, you'd get meaningless numbers all over the map.

What I have done is something similar to what you're trying, but with a For/Next
loop around the code in question to make it execute 1,000 times or a 1,000,000
times or whatever is necessary to make the lines of code take perhaps 30 seconds
to execute.

In that sort of time frame you can either do something like you're trying, or
even just use a stop watch on it.

Good luck...

Bill
 
B

Bill Martin

ajocius said:
Group,
I'm trying to find out how long blocks of code take to execute in
order to balance my program. Below is a sample of programming I'm
using to attempt this. I doesn't seem to work. Any help for a novice
would be awesome.

Dim StartTime As Long
Dim EndTime As Long
Dim TotalTime As Long
..
..
..
..
..
StartTime = Now()
..
..
..
EndTime = Now()
TotalTime = EndTime - StartTime





Tony

If you're trying to time a few lines of code, I don't know how you can do it
directly given the vagaries of applications interacting with the operating
system. Even if you could do it, you'd get meaningless numbers all over the map.

What I have done is something similar to what you're trying, but with a For/Next
loop around the code in question to make it execute 1,000 times or a 1,000,000
times or whatever is necessary to make the lines of code take perhaps 30 seconds
to execute.

In that sort of time frame you can either do something like you're trying, or
even just use a stop watch on it.

You'll also need to check an empty For/Next loop to see how long that takes and
subtract it from the totals you get.

Good luck...

Bill
 

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