ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - Timing A Block Of Lines (https://www.excelbanter.com/excel-programming/346597-vba-timing-block-lines.html)

ajocius[_42_]

VBA - Timing A Block Of Lines
 

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


--
ajocius
------------------------------------------------------------------------
ajocius's Profile: http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=488186


Bill Martin[_2_]

VBA - Timing A Block Of Lines
 
ajocius wrote:
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

Bill Martin[_2_]

VBA - Timing A Block Of Lines
 
ajocius wrote:
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


All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com