Extended Timer and TimeStamp
#4
Note:  Strings are inherently slow, so if you need a time stamp for use inside a loop, use the integer64 version above.  For example, try the code here:

Code: (Select All)
Type SYSTIME
    year As Integer
    month As Integer
    weekday As Integer
    day As Integer
    hour As Integer
    minute As Integer
    second As Integer
    millis As Integer
End Type
Declare Dynamic Library "Kernel32"
    Sub GetSystemTime (lpSystemTime As SYSTIME)
    Sub GetLocalTime (lpSystemTime As SYSTIME)
End Declare

Dim st As SYSTIME
Dim As _Integer64 count, count1

GetSystemTime st
Print st.year, st.month, st.day, st.weekday
Print st.hour, st.minute, st.second, st.millis

GetLocalTime st
Print st.year, st.month, st.day, st.weekday
Print st.hour, st.minute, st.second, st.millis

Do
    _Limit 100
    Locate 10, 1: Print " "; LocalTimeStamp$
    Print LocalTimeStamp64
Loop Until _KeyHit

Print "Timing routines for 5 seconds each:"
t# = Timer + 5
Do Until Timer > t#
    count = count + 1
    test$ = LocalTimeStamp$
Loop

t# = Timer + 5
Do Until Timer > t#
    count1 = count1 + 1
    t = LocalTimeStamp64
Loop

Print "In 5 seconds, each routine ran:"
Print Using "###,###,###,### (String)"; count
Print Using "###,###,###,### (int64)"; count1


Function LocalTimeStamp$
    Dim st As SYSTIME
    GetLocalTime st
    t$ = AddString(t$, st.year, 4)
    t$ = AddString(t$, st.month, 2)
    t$ = AddString(t$, st.day, 2)
    t$ = AddString(t$, st.weekday, 1)
    t$ = AddString(t$, st.hour, 2)
    t$ = AddString(t$, st.minute, 2)
    t$ = AddString(t$, st.second, 2)
    t$ = AddString(t$, st.millis, 3)
    LocalTimeStamp = t$
End Function

Function LocalTimeStamp64~&&
    Dim st As SYSTIME: GetLocalTime st
    LocalTimeStamp64 = st.year * 1E14 + st.month * 1E12 + st.day * 1E10 + st.weekday * 1E9 + st.hour * 1E7 + st.minute * 1E5 + st.second * 1E3 + st.millis
End Function



Function AddString$ (what$, value As _Integer64, minDigits As Integer)
    v$ = Right$(String$(minDigits, "0") + _Trim$(Str$(value)), minDigits)
    AddString = what$ + v$
End Function


I get about 3 million calls to the string version of the timestamp, and about 56 million calls to the integer64 version.  Numbers are just faster than excessive amounts of string manipulation like this.  Wink
Reply


Messages In This Thread
Extended Timer and TimeStamp - by SMcNeill - 04-20-2022, 02:17 AM
RE: Extended Timer and TimeStamp - by dcromley - 04-22-2022, 07:30 PM
RE: Extended Timer and TimeStamp - by SMcNeill - 01-02-2023, 05:37 AM
RE: Extended Timer and TimeStamp - by SMcNeill - 01-02-2023, 01:30 PM



Users browsing this thread: 4 Guest(s)