Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
Is there a way for VBA to capture how long it takes for a piece of code or
user defined function to run? Like how fast it is on calculating a simple UDF? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
try something like this...
Sub test() Dim lng As Long Dim dblStartTime As Double Dim dblEndTime As Double dblStartTime = Timer For lng = 0 To 100000000 Next lng dblEndTime = Timer MsgBox "Duration " & dblEndTime - dblStartTime End Sub -- HTH... Jim Thomlinson "John" wrote: Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
Hi John,
John wrote: Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? You can use the Timer function: Dim sngTimer As Single sngTimer = Timer '/ your code Debug.Print Timer - sngTimer The resolution isn't great on the Timer function, so you may get 0 for UDFs that don't take long to execute. For better results, you could try the GetTickCount API function (resolution of about 10ms): http://www.vbforums.com/showthread.php?t=231183 -- Regards, Jake Marx www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
thanks Jim I will play with this... although my first thought is... I wonder
if adding this code to code makes it slower... it must... but I can add new code and still see the difference. "Jim Thomlinson" wrote: try something like this... Sub test() Dim lng As Long Dim dblStartTime As Double Dim dblEndTime As Double dblStartTime = Timer For lng = 0 To 100000000 Next lng dblEndTime = Timer MsgBox "Duration " & dblEndTime - dblStartTime End Sub -- HTH... Jim Thomlinson "John" wrote: Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
John wrote:
Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? :) Declare Function GetTickCount Lib "kernel32" () As Long Dim longStart As Long, longStop As Long longStart = GetTickCount ...... longStop = GetTickCount |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
first, Timer is a single, so you might want to stick with declaring your
timer related variables as single. from the immediate window (for confirmation) ? typename(timer) Single Second, Jim only put that loop in there as a demonstration of how to time some sample code. You would replace that loop portion with the working portion of your current code - the commands you want to time. If you understood that, then my apologies - but there are many responses that come back to suggestions such as this that indicate they don't. -- Regards, Tom Ogilvy "John" wrote: thanks Jim I will play with this... although my first thought is... I wonder if adding this code to code makes it slower... it must... but I can add new code and still see the difference. "Jim Thomlinson" wrote: try something like this... Sub test() Dim lng As Long Dim dblStartTime As Double Dim dblEndTime As Double dblStartTime = Timer For lng = 0 To 100000000 Next lng dblEndTime = Timer MsgBox "Duration " & dblEndTime - dblStartTime End Sub -- HTH... Jim Thomlinson "John" wrote: Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Time to complete code/function
interesting, thanks one and all for the replies
"witek" wrote: John wrote: Is there a way for VBA to capture how long it takes for a piece of code or user defined function to run? Like how fast it is on calculating a simple UDF? :) Declare Function GetTickCount Lib "kernel32" () As Long Dim longStart As Long, longStop As Long longStart = GetTickCount ...... longStop = GetTickCount |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I complete increments of time in column A by say 9 min? | Excel Discussion (Misc queries) | |||
Subtotalling taking long time to complete | Excel Worksheet Functions | |||
Reading complete Excel using DDE code | Excel Programming | |||
Complete Newbe - Is this a MACRO function or VB ? | Excel Programming | |||
Run time - % complete | Excel Programming |