Jump to content

Timing Question(s)


Recommended Posts

First question:

Do you get the same variations in the amount of delay caused by each section in the code below?

While 1
    
    $start1 = TimerInit()
    Sleep(100)
    $stop1 = TimerDiff($start1)
    
    $start2 = TimerInit()
    For $i = 1 To 1
        Sleep(100)
    Next
    $stop2 = TimerDiff($start2)
    
    $start3 = TimerInit()
    For $i = 1 To 10
        Sleep(10)
    Next
    $stop3 = TimerDiff($start3)
    
    $start4 = TimerInit()
    For $i = 1 To 100
        Sleep(1)
    Next
    $stop4 = TimerDiff($start4)
    
    MsgBox(0, "", "$stop1 = " & $stop1 & @CR & _
                  "$stop2 = " & $stop2 & @CR & _
                  "$stop3 = " & $stop3 & @CR & _
                  "$stop4 = " & $stop4)
    
WEnd

My output is about like this:

$stop1 = 97.48...

$stop2 = 99.52...

$stop3 = 100.12...

$stop4 = 1001.7...

Second question:

I assume that this has been demonstrated before in some other post. How would one search for it? (What text to enter on the forum's search line?)

Edit: From a subsequent post of mine:

I have no problem with the AutoIt Sleep function as is and have no scripts requiring greater timing accuracy. I should have placed a greater emphasis on question 2 in my original post - how to search the forum for such info.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

To me in bring's up the topic about how a Select...EndSelect statement is faster to execute then an If...EndIf statement, I guess it applies for For...Next loop's aswell? ie. How many time's it has to loop etc.

Edited by Burrup

qq

Link to comment
Share on other sites

Here's the output for my system:

$stop1 = 104.450705327074

$stop2 = 109.351328171597

$stop3 = 156.507880191477

$stop4 = 1562.30694124533

I don't understand how your system gave results under 100ms for your first two tests. Could this possibly be a bug?

To me it does make sense that the results differ since AutoIt has to move around the script code more and more for each progressive test. I must admit that I'm surprised to see the rather large result for the final test.

Regards,

Alex Peters

Link to comment
Share on other sites

Possibly CPU speed is a factor? 2.4Ghz, 738mb DDR ram. These are results...

$stop1 = 106.7...

$stop2 = 107.4...

$stop3 = 107.3...

$stop4 = 1075.2...

Edit: After more testing I am getting results all over the place. Below are numbers arranging the testing from least time (1) to most time (4).

3  1 < Close    3

1  3                  2

2  2 < Close    1

4  4                  4

Most of the times were not as close as my first test but more then often 10ms apart in some cases.

Edited by Burrup

qq

Link to comment
Share on other sites

Thanks for the info and confirmation. I understand why it happens... I just wanted to make sure that my numbers were in line with others and I could not find such confirmation during my first search of the forum.

Any suggestions on question two?

I assume that this has been demonstrated before in some other post. How would one search for it? (What text to enter on the forum's search line?)

Entering a search string like

+TimerInit+Sleep

returned a lot to read...

I was hoping for a better search string, perhaps adding "accurate" would have helped me to find this post sooner:

http://www.autoitscript.com/forum/index.ph...indpost&p=47734

@Burrup,

Yes, I noticed the variation between each While/Wend loop (See Jon's post above). That is why I added the While/Wend loop to the sample code - makes it easy for people to see the "variations of the variations" - if I may use such English. This is not a problem for me as I do not need the code - I just stumbled across this while writing a Do/Until loop to answer another post.

Thanks all...........

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Within the same While/WEnd loop:

$stop1 = 90.8...

$stop4 = 1036.4...

On a print/file server running XP SP2 (166Mhz w/ 64MB RAM) under the load of running the Remote Desktop connection used to run the script.

later....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I got a:

$stop1 = 107.32105247681

$stop2 = 107.424437771802

$stop3 = 108.426211939528

$stop4 = 1074.56030111841

Well..I'm going to assume it's not a CPU problem because I'm running XP SP1 on a P4 3.0Ghz with 1GB DDR RAM..:)..Specs shouldn't be a problem

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

  • 2 weeks later...

See this chain in support discussing more accurate sleep times for low sleep times (work around request)

http://www.autoitscript.com/forum/index.ph...opic=13415&st=0

and this chain in Idea Lab re making it better (it has code for more accurate longer fortimes, but still not very accurate for short times)

http://www.autoitscript.com/forum/index.php?showtopic=13605

when I run this code, I get 107,113,151,1562 msec for the four stops.

That must mean that the sleep function is dependent on the machine in some fashion. My pc sleeps for about 15 msec for any parameter less than 15 msec. The original post sleeps close to 10 msec for 10 and under. edit: Both look to be duplicated on other machines.

I have WXP, home edition, fully updated SP2 and patches, 3.05GHZ P4, HT turned off.

What do you have?

Regards

Larry

Edited by lgodfrey

I'm, Lovin' IT, X

Link to comment
Share on other sites

...when I run this code, I get 107,113,151,1562 msec for the four stops.

<snipped>

I have WXP, home edition, fully updated SP2 and patches, 3.05GHZ P4, HT turned off.

What do you have?

Regards

Larry

<{POST_SNAPBACK}>

Interesting, you and LxP get 1562... of course running it over and over can show some big swings.

Wild guess here: The CPU/speed/RAM/... does not seem to be as critical as the number of processes taking a slice of the overall processing pie. Take a look at the times posted for the XP SP2 (166Mhz w/ 64MB RAM) system. The original post numbers came from XP SP2 P4 (1.7Ghz w/ 512MB RAM). Both systems have most of the useless services turned off - like I need the "Wireless Zero Configuration" service running on an office desktop.

have fun...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Sleep(1) will be anything up to 15ms so that the margin of error becomes massive when looping...

<{POST_SNAPBACK}>

In an earlier post, I said, "I understand why it happens... ". Perhaps I should have said that I had already located your post from Dec of 2004 on this topic and the I understand *that* it happens. I do not need/care to know why.

I have no problem with the AutoIt Sleep function as is and have no scripts requiring greater timing accuracy. I should have placed a greater emphasis on question 2 in my original post - how to search the forum for such info.

Thanks Jon (and developers) for all that you do for AutoIt.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Wild guess here: The CPU/speed/RAM/... does not seem to be as critical as the number of processes taking a slice of the overall processing pie. Take a look at the times posted for the XP SP2 (166Mhz w/ 64MB RAM) system. {LAG: this "low end" machine had sleep(1)~=sleep(1)}

<{POST_SNAPBACK}>

My system, same OS, "faster" cpu, 2gig ram, gives sleep(1)~-sleep(15), with or without HT on. I am not sure the guess is right though...Task Manager reports close to zero CPU time useage with or without sleeping, even with 52 processes running.

Regards

Larry

I'm, Lovin' IT, X

Link to comment
Share on other sites

Not suprised that my wild guess is probably wrong.

Maybe Jon's comment in post 10 can be added to the documentation until the Sleep function is changed - if it is going to be changed.

Just for fun: run this with and without the msgbox:

FileOpen("c:\temp\Sleep-test.csv",2)

For $i = 1 to 100
    $start1 = TimerInit()
    Sleep(1)
    $stop1 = TimerDiff($start1)
    
    MsgBox(0, "", "$stop1 = " & $stop1)
    FileWrite("c:\temp\Sleep-test.csv", $stop1 & @CR)
Next

FileClose("c:\temp\Sleep-test.csv")
then sort for low numbers:

0.222965139

0.487492125

0.51768898

0.822171533

0.871060428

0.974146155

1.096228711

1.519746225

2.243022507

above with msgbox - below msgbox commented out

1.285867059

9.656813925

10.28734099

10.82372201

11.2274046

11.5157094

I never got value less than one with the msgbox commented out and I rarley got a 1.xx. I had to run it over and over to get that. The first value is usually the lowest for me.

Again, let me be clear that I'm not complaining about the Sleep function as it is currently written. I do however want users to be aware of what to expect with settings below Sleep(15).

later....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...