Per ggregg:
Or is there a better way?
Thank you for any suggestions
Something that's probably not immediately relevant - due to all
the expertise applied to the OP - but which will eventually be
useful to you: The TickCount() API call.
Using it, you can put together a little routine that measures the
time diff between calls to it.
With such a routine it's easy to test two different approaches
and see which is faster. If the approaches do so little work
that thousandths of a second are too big, just write a loop to
repeat each approach 100, 1,000, 10,000 or however many times is
needed to get relevant info.
Code below is probably wretched excess, but you'll be able to get
the general idea from reading it.
----------------------------------------------------------------
Private Declare Function GetTickCount_lti Lib "kernel32" Alias
"GetTickCount" () As Long
Public Sub LogTime(ByVal theStartNewSwitch As Integer, ByVal
theLogEntry As String)
2000 debugStackPush mModuleName & ":LogTime"
2001 On Error GoTo LogTime_err
' PURPOSE: Provide a tool for benchmarking performance by
writing begin/end
' running times to an ASCII text file.
' ACCEPTS: Boolean telling whether-or-not this is the
beginning of a set of observations
' and a String describing the process being timed.
' USES: .INI file parameter "LogPath"
' OUTPUTS: ...to a log file
' NOTES: 1) Writes two times to the text file:
' > Since the previous invocation (i.e. the last
step...)
' > Cumulative since the first invocation with
'theStartNewSwitch=True'
' 2) The .INI file parameter does double duty. We
also use it as a switch to turn
' logging on and off. If not present, we exit
the this routine without making a log entry.
' 3) If we have a bad log file directory, we don't
want to trash up the error log with
' a bazillion entries (i.e. every time we call
LogTime()), hence the "BadLogFileNoted" switch.
2010 Static myLogPath As String
Static myCurrentUser As String
Static myMachineName As String
Static myCurrentVersion As String
Static SeqNum As Long
Static BadLogFileNoted As Boolean
Static prvTimeMS As Long ' ms marking, previous
time
Static beginTimeMS As Long ' ms marking, Beginning
time
Static sincePrevMS As Long ' ms marking, elspsed
since previous time
Static sinceBeginMS As Long ' ms marking, elspsed
since begin time
Dim currentMSMarking As Long ' ms marking, current
hash marking
Dim ParmValue As String
Dim L As Long
Dim i As Integer
Dim X As Integer
2020 Const defaultPath = "C:\TEMP"
2030 ParmValue = String(255, 0)
2031 ParmValue = Space(255)
2032 L = GetPrivateProfileString_lti("programParms", "LogPath",
"{NotFound}", ParmValue, 255, SysCmd(acSysCmdIniFile))
2040 If L And Left(ParmValue, 10) <> "{NotFound}" Then
2050 myLogPath = Left(ParmValue, L)
2060 If dirExist_lti(myLogPath) = False Then
2070 If BadLogFileNoted = False Then
2071 BugAlert False, "Invalid log path: '" & myLogPath &
"'."
2072 BadLogFileNoted = True
2073 End If
2080 Else
2100 If theStartNewSwitch = True Then
2110 myCurrentUser = CurrentUserGet()
2111 myMachineName = MachineNameGet()
2120 If Len(myMachineName) = 0 Then
2121 myMachineName = myCurrentUser
2122 End If
2130 If Len(myCurrentVersion) = 0 Then
2131 myCurrentVersion = currentVersionGet_lti()
2132 End If
2210 End If
2220 X = FreeFile
2240 myLogPath = myLogPath & "\" & "$" & myMachineName &
".txt"
2241 Open myLogPath For Append As X
2290 If theStartNewSwitch = True Then
2300 SeqNum = 0
2310 beginTimeMS = GetTickCount_lti
2320 prvTimeMS = beginTimeMS
2330 sinceBeginMS = 0
2340 sincePrevMS = 0
2350 Print #X, myCurrentVersion & "
--------------------- " & myCurrentUser & " " & Format$(Now,
"MM-DD-YYYY HH:NN:SS") & " -----------------------------"
2360 End If
2365 SeqNum = SeqNum + 1
2370 currentMSMarking = GetTickCount_lti '* Mark time in ms
2390 sinceBeginMS = currentMSMarking - beginTimeMS '*
Use same time marking in both calculations
2400 sincePrevMS = currentMSMarking - prvTimeMS '*
Use same time marking in both calculations
2410 Print #X, myCurrentVersion & " " & myCurrentUser & " "
& Format$(SeqNum, "@@@") _
& " " & Format(sincePrevMS \ 1000, "@@@@") &
"." & Format(sincePrevMS Mod 1000, "000") _
& " " & Format(sinceBeginMS \ 1000, "@@@@")
& "." & Format(sinceBeginMS Mod 1000, "000") _
& " " & theLogEntry
2500 prvTimeMS = currentMSMarking
2998 End If
2999 End If
LogTime_xit:
DebugStackPop
On Error Resume Next
Close #X
Exit Sub
LogTime_err:
BugAlert True, ""
Resume LogTime_xit
End Sub