Hi,
Does anyone know if it's possible to get the exact time in milliseconds or microseconds and store it into a variable? The only command I have been using is the "Sec>" command, but it returns the current number of seconds in whole seconds rather than milliseconds. Any help would be greatly appreciated. Thanks so much in advance!
~Len
Getting exact time (milliseconds or microseconds)
Moderators: JRL, Dorian (MJT support)
I could only think of two ways to get fractions of a second. Using the VBScript timer and using the TimeStamp> function. There might be a way using LibFunc> but I don't have time to research that option.
The following script runs for 5 seconds then pops the results into notepad. It simply loops and in each loop cycle uses the TimeStamp> function to write the cycle count and the VBScript "Timer" result to a file.
I found this test very revealing. Any machinist will immediately recognize the VBscript output as 64ths of a second. Oddly or maybe not so oddly that is the same interval that TimeStamp> reports.
I'm wondering if this is software specific, Operating System specific, or CPU chip specific? Can we really and accurately divide seconds any finer than 1/64 of a second? When I enter a wait>0.01 am I getting a 1/100th of a second wait or a 1/64th of a second wait?
The following script runs for 5 seconds then pops the results into notepad. It simply loops and in each loop cycle uses the TimeStamp> function to write the cycle count and the VBScript "Timer" result to a file.
I found this test very revealing. Any machinist will immediately recognize the VBscript output as 64ths of a second. Oddly or maybe not so oddly that is the same interval that TimeStamp> reports.
I'm wondering if this is software specific, Operating System specific, or CPU chip specific? Can we really and accurately divide seconds any finer than 1/64 of a second? When I enter a wait>0.01 am I getting a 1/100th of a second wait or a 1/64th of a second wait?
Code: Select all
IfFileExists>%temp_dir%seconds.txt
DeleteFile>%temp_dir%seconds.txt
EndIf
WriteLn>%temp_dir%seconds.txt,wres,DATESTAMP%TAB%%TAB%CYCLE%TAB%VBSCRIPT%crlf%
VBSTART
VBEND
VBEval>Timer,StartTime
Let>kk=0
Label>start
Add>kk,1
VBEval>Timer,thistime
DateStamp>%temp_dir%seconds.txt,%TAB%%kk%%TAB%%thistime%
VBEval>Timer-%StartTime%,TotalTime
If>TotalTime<5,start
Run>notepad.exe %temp_dir%seconds.txt
Exit>0
Time to process a step
Is the limitation the smallest time interval VBScript will report or is it how quickly Macro Scheduler and VBScript can process commands?
In your output is the same time reported for two or more report lines in a row?
In your output is the same time reported for two or more report lines in a row?
I'm pretty sure its the smallest time interval VBScript and Macro Scheduler will report. Possibly the smallest time interval the computer is capable of reporting.
The computer is writing about 19,500 lines in 5 seconds so each time interval displays on roughly 60 consecutive lines. For each written line 6 lines of Macro Scheduler script is processed. If my math is correct that's 360 lines of script processed each 1/64th of a second. I don't think script processing lag has anything to do with this.
The computer is writing about 19,500 lines in 5 seconds so each time interval displays on roughly 60 consecutive lines. For each written line 6 lines of Macro Scheduler script is processed. If my math is correct that's 360 lines of script processed each 1/64th of a second. I don't think script processing lag has anything to do with this.
After some investigation I found that Windows Nt default timer resolution is 1/64th of a second. There are some multimedia timers available via Library functions. To investigate, start searching Microsoft's web site for "Windows NT High Resolution Timers".
Using The multimedia Library function "timeGetTime" we can retrieve millisecond time intervals. "timeGetTime" reports the number of milliseconds that have elapsed since Windows was started. Here is the above script with "timeGetTime" added to it.
Hope this is helpful.
Using The multimedia Library function "timeGetTime" we can retrieve millisecond time intervals. "timeGetTime" reports the number of milliseconds that have elapsed since Windows was started. Here is the above script with "timeGetTime" added to it.
Hope this is helpful.
Code: Select all
IfFileExists>%temp_dir%seconds.txt
DeleteFile>%temp_dir%seconds.txt
EndIf
WriteLn>%temp_dir%seconds.txt,wres,DATESTAMP%TAB%%TAB%CYCLE%TAB%VBSCRIPT%TAB%timeGetTime%crlf%
VBSTART
VBEND
VBEval>Timer,StartTime
Let>kk=0
Label>start
Add>kk,1
VBEval>Timer,thistime
LibFunc>Winmm,timeGetTime,tGTres,
DateStamp>%temp_dir%seconds.txt,%TAB%%kk%%TAB%%thistime%%TAB%%tgtres%
VBEval>Timer-%StartTime%,TotalTime
If>TotalTime<5,start
Run>notepad.exe %temp_dir%seconds.txt
Exit>0