ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time a sub routine in thousanths of a second (https://www.excelbanter.com/excel-programming/281389-time-sub-routine-thousanths-second.html)

Rocky McKinley

Time a sub routine in thousanths of a second
 
With the following code provided by this forum I'm able to pause a sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley





jaf

Time a sub routine in thousanths of a second
 
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in

thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley







Rocky McKinley

Time a sub routine in thousanths of a second
 
John, I tried your code and I get an error "Sub or Function not defined."

--
Regards,
Rocky McKinley


"jaf" wrote in message
...
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in

thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley









Vasant Nanavati

Time a sub routine in thousanths of a second
 
Hi Rocky:

Sub TimeIt()
Dim StartTime As Double
StartTime = Timer
'lots of code here
MsgBox Format((Timer - StartTime)*1000, "#.00") & " milliseconds"
End Sub

Regards,

Vasant.




"Rocky McKinley" wrote in message
...
John, I tried your code and I get an error "Sub or Function not defined."

--
Regards,
Rocky McKinley


"jaf" wrote in message
...
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in

thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley











Tom Ogilvy

Time a sub routine in thousanths of a second
 
Sub test()
t=timer '<===
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub

--
regards,
Tom Ogilvy

Rocky McKinley wrote in message
...
John, I tried your code and I get an error "Sub or Function not defined."

--
Regards,
Rocky McKinley


"jaf" wrote in message
...
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in

thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley











Rocky McKinley

Time a sub routine in thousanths of a second
 
Thanks Guys

--
Regards,
Rocky McKinley


"Tom Ogilvy" wrote in message
...
Sub test()
t=timer '<===
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub

--
regards,
Tom Ogilvy

Rocky McKinley wrote in message
...
John, I tried your code and I get an error "Sub or Function not

defined."

--
Regards,
Rocky McKinley


"jaf" wrote in message
...
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a

sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in
thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley













Bob[_38_]

Time a sub routine in thousanths of a second
 
I use the class control provided by Karl Peterson for VB which should work
with VBA, grate for timing big storage loops etc

It uses the OS Multimedia timer and is very accurate and very easy to
stop/start.

he also has tip sheet about using

Can be found at http://www.mvps.org/vb/ file Stopwatch.zip

to use
add class to VBA project and in your code especially loops ...

'Create instance of stopwatch class
Set tmr = New CStopWatch
tmr.Reset


'to end after your code
StorageTime = tmr.Elapsed
LogFile "TIME for Data Storage:" & CStr(StorageTime / 1000) & " secs"

Cheers

Bob

"Rocky McKinley" wrote in message
...
Thanks Guys

--
Regards,
Rocky McKinley


"Tom Ogilvy" wrote in message
...
Sub test()
t=timer '<===
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub

--
regards,
Tom Ogilvy

Rocky McKinley wrote in message
...
John, I tried your code and I get an error "Sub or Function not

defined."

--
Regards,
Rocky McKinley


"jaf" wrote in message
...
Hi Rocky,
Sub test()
t-timer
'lots of code
t1=timer
debug.print t1-t 'or msgbox t1-t
end sub


--

John

johnf202 at hotmail dot com


"Rocky McKinley" wrote in message
...
With the following code provided by this forum I'm able to pause a

sub
routine in thousanths of a second.
Is there a way to time how long it takes a sub routine to run in
thousanths
of a second?


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepOneSecond()
Sleep 1000
End Sub

--
Regards,
Rocky McKinley
















All times are GMT +1. The time now is 04:22 AM.

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