Serving the Quantitative Finance Community

 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

vb

June 8th, 2004, 12:53 pm

basic question but in vb how do i write a piece of code which times how long my sub takes to run?
 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

vb

June 8th, 2004, 1:00 pm

got it..but how do i convert to seconds rather than days?
 
User avatar
vh
Posts: 0
Joined: April 1st, 2004, 9:25 pm

vb

June 8th, 2004, 1:10 pm

Are you using the Now() function? Use DateDiff on two dates to return the number of seconds between them.An alternative is the use Timer() function which returns the number of seconds elapsed since midnight. Obviously this causes a problem if your subroutine is running from 23:59 to 00:01, but it's easily solved.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

vb

June 8th, 2004, 1:22 pm

You possibly need something with a bit higer resolution than a second...You can call the Win32 API function GetTickCount, by putting this in a module, which will give you the number of milliseconds since the system booted.Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

vb

June 8th, 2004, 1:31 pm

vhthanks for the tip DateDiff works like a charmhowever as pointed out by DCFC seconds is the highest accuracy availableDCFCHow do I incorporate the GetTickCount function into the sub. I'm currently using the DateDiff function
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

vb

June 8th, 2004, 1:48 pm

Dim start As Longstart = GetTickCount()'do stuffDebug.Print GetTickCount() - start
 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

vb

June 8th, 2004, 2:07 pm

Many thanks DCFC!!