Jump to content
Sign in to follow this  
Bowmore

@MSEC macro appears to only have a resolution of 15 or 16 milliseconds.

Recommended Posts

Bowmore

I have Noticed

tested on XP SP3 running a Pentium P4 3.2GHz Processor using AutoiIt 3.3.0.0 and Beta 3.3.1.1

In the first loop returns the value only changes approximately every 250 in jumps of 15 or 16

In the second loop with the 15 millisecond sleep @MSEC returns a different each time as expected.

Is this a bug or the limit of AutoIt's time resolution?

For $i = 1 To 1000
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @MSEC = ' & @MSEC & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

For $i = 1 To 1000
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @MSEC = ' & @MSEC & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Sleep(15)
Next
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
martin

I have Noticed

tested on XP SP3 running a Pentium P4 3.2GHz Processor using AutoiIt 3.3.0.0 and Beta 3.3.1.1

In the first loop returns the value only changes approximately every 250 in jumps of 15 or 16

In the second loop with the 15 millisecond sleep @MSEC returns a different each time as expected.

Is this a bug or the limit of AutoIt's time resolution?

For $i = 1 To 1000
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @MSEC = ' & @MSEC & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

For $i = 1 To 1000
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @MSEC = ' & @MSEC & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Sleep(15)
Next
It looks like @MSEC is accurate to around 15 or 16 mS.

Dim $times[2][1000]
$count = 1
$times[0][0] = 0
$lastcount = -9
$tt = timerinit()
while $count < 1000
    $times[0][$count] = timerdiff($tt)
    $times[1][$count] = @MSEC
    If $times[0][$count] <> $times[0][$count - 1] then $count += 1
wend
for $i = 1 to $count
ConsoleWrite('TimerDiff, @MSEC = ' & StringFormat("%5.5f, %d",$times[0][$i],$times[1][$i]) & @CRLF);### Debug Console
Next

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Bowmore

It looks like @MSEC is accurate to around 15 or 16 mS.

Dim $times[2][1000]
$count = 1
$times[0][0] = 0
$lastcount = -9
$tt = timerinit()
while $count < 1000
    $times[0][$count] = timerdiff($tt)
    $times[1][$count] = @MSEC
    If $times[0][$count] <> $times[0][$count - 1] then $count += 1
wend
for $i = 1 to $count
ConsoleWrite('TimerDiff, @MSEC = ' & StringFormat("%5.5f, %d",$times[0][$i],$times[1][$i]) & @CRLF);### Debug Console
Next
@Martin

That's the conclusion I have come to.

After experimenting with calling GetSystemTime() directly and searching MSDN I have found that this is a hardware limitation. The clock on most systems apparently, is only updated 64 times a second giving the 15 to 16 millisecond step observed.

That means that this is definately not an AutoIt bug, but possibly the documation needs to be updated to point out this limitation.

There are of course ways of getting millisecond or even sub millisecond time differences.

In my searches found the following on MSDN. This artical contains some very interesting explanations and C code for achieving high precision time. For those that require time to an accuracy of greter than 15 milliseconds I should not be too difficult to impliment this as a UDF. Personally I don't need this level of accuracy, my original question was just out of quriosity for something I had observed.

Artical on how to get high precision time

$str = "ushort varYear;ushort varMon;ushort varDofW;ushort varDay;ushort varHour;ushort varMin;ushort varSec;ushort varMsec"
$st = DllStructCreate($str)
$pst = DllStructGetPtr($st)
For $i = 1 To 1000
$result = DllCall("Kernel32.dll", "none", "GetSystemTime", "ptr",$pst)
$year = DllStructGetData ( $st, "varYear" )
$month = DllStructGetData ( $st, "varMon" )
$day = DllStructGetData ( $st, "varDay" )
$hour = DllStructGetData ( $st, "varHour" )
$min = DllStructGetData ( $st, "varMin" )
$sec = DllStructGetData ( $st, "varSec" )
$msec = DllStructGetData ( $st, "varMsec" )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :Date Time = ' & $year & "-" & $month & "-" & $day & " " & $hour & ":" & $min & ":" &  $sec & ":" & $msec & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.