Link to home
Start Free TrialLog in
Avatar of mkeysaer
mkeysaer

asked on

Capture sub second response times in VB

I am writing a utility to use for performance testing.  Does anyone know of a VB function I can invoke to capture sub second response times or a way that I can create my own.  The standard now() function only returns the value of the system clock which does not break down the time futher than a second.  Likewise the date functions do not support sub second time intervals either.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use    Timer    ...  it gives it in times accurate lessa than a second by returning a single...  ie. 82390.95

Good Luck.
I'm with Anthony, you can write you codes to test the time bypassed like this:

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
    Dim strTime As Long, stpTime As Long
    strTime = GetTickCount
   
    'Do the process here
    For i = 1 To 1000
        DoEvents
        Debug.Print i
    Next i
   
    'strTime returns time in miliseconds (1000 = 1 second)
    strTime = GetTickCount - strTime
   
    'Convert it to 2 decimal format
    MsgBox Format$(strTime / 1000, "#.00")
End Sub
Avatar of mcoop
mcoop

I thought ticks are approx 18mS resolution... ?  (i.e. backward compatible with the old DOS clock...)

Does anyone know the correct answer ??

Sorry ryancs - I just want to make sure for my own knowledge as well !
Yea... but  Timer  is basically the VB way of doing it...  like you would use MsgBox rather than the MessageBox Win API or like you would do text1.text = ""  rather than SendDlgItemMessage or SendMessage w/ WM_SETTEXT   Both ways work great, though

Good luck!
Hi,
When I developed profiler application for myself I used this:

Private Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer" & ProfSpecLine
  wDay As Integer" & ProfSpecLine
  wHour As Integer" & ProfSpecLine
  wMinute As Integer" & ProfSpecLine
  wSecond As Integer" & ProfSpecLine
  wMilliseconds As Integer" & ProfSpecLine
End Type

Private Declare Sub GetSystemTime Lib ""kernel32"" (ByRef lpSystemTime As SYSTEMTIME)

After that you can do

Dim A as SYSTEMTIME
GetSystemTime A

and access A.wYear ... A.wMilliseconds.

Sincerely,
Crin

Avatar of mkeysaer

ASKER

A lot of good answers.  Thanks for the input everyone!