Sign in to follow this  
Followers 0
codewalker

Looping Question

12 posts in this topic

Hi,

Is there a difference in using a WHILE...WEND loop vs a DO...UNTIL loop performance wise? I have a DO...UNTIL infinite loop with a condition in it to exit the loop and a SLEEP command to hopefully help but some users experience performance issues. Any tips on using infinite loops without degrading performance?

Share this post


Link to post
Share on other sites



Yes, there is.

While: The expression is tested before the loop is executed.

Do Until: The expression is tested after the loop is executed.

So the Do Until Loop runs at least once.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes, there is.

While: The expression is tested before the loop is executed.

Do Until: The expression is tested after the loop is executed.

So the Do Until Loop runs at least once.

Thanks for the reply. That i know but is there a difference in their performance? Noticed that most of the infinite loop examples in the forums use WHILE...WEND, is there an advantage in using it againts DO...UNTIL? I used DO...UNTIL in one of my scripts and it's slowing down some users workstations. Any ideas?

Share this post


Link to post
Share on other sites

I don't think there is a difference in performance:

$iIndex = 0
$iLoops = 10000000
$iTimer = TimerInit()
While $iIndex < $iLoops
    $iIndex = $iIndex + 1
Wend
ConsoleWrite(TimerDiff($iTimer) & @CRLF)
$iIndex = 0
$iTimer = TimerInit()
Do
    $iIndex = $iIndex + 1
Until $iIndex > $iLoops
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

returns:

9259.90794696208

9207.17102991027

here


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks! Any ideas though on how or why an infinite loop would cause a program executed via a RUN command before the loop to freeze? Does having a SLEEP command in the loop have any effect on responsiveness?

Edited by codewalker

Share this post


Link to post
Share on other sites

If you can post the code (at least the part with the loop) we can have a look at it.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

If you can post the code (at least the part with the loop) we can have a look at it.

Its something like this...

Run(...)

Do

Sleep(1000)

...

If Not ProcessExists(...) Then Exit 0

...

Until ...

I was using WINEXISTS before but learned that there were a lot of factors that would NOT trigger it so i went and used loops instead. Using the script indicated above causes the program that was launched by the RUN command to lockup, at least with some users.

Edited by codewalker

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You have two conditions to exit the loop. One is "If Not processExists ..." the other is "Until ...". is this what you intend to do?

If you just want to wait until the process has stopped then I would suggest to use something like this:

While 1
   Sleep(1000)
   ...
   If Not ProcessExists(...) Then Exit 0
Wend
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Codewalker,

i tried Water example i got the below values:

For While loop - 12762.1928057139

For Di Loop - 12770.5848202678

There is 8 ms difference between both definite loop. If you are saying you have indefinite loop then i could suggest to go for While ...wend to more quick results....As for as i don;t know the reason but i will try to find out:).... Water please correct me if i am wrong... There may be a chances of machine capacity for response.. I am having 1GB Ram so i got the response time of above if water response time is less than mine so his machine may faster then mine.... so also try to look in to that way to trouble shoot it.... :mellow:


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

Hi Syed,

I don't think the speed difference is a matter of RAM. It's a matter of CPU speed and X86 vs. X64.

Run as X86 it takes about 11300 ms, run as X64 it takes about 9200 ms.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks for the replies guys.

This maybe unrelated but just read somewhere that there are instances that SLEEP locks up or hangs the whole process...at least in VB. Could that be what is causing the lockup in my script? Their fix was to have a DOEVENTS but is there a similar command in AutoIt?

Share this post


Link to post
Share on other sites

There are situations where a Sleep in your code is a bad idea. A function registered by AdlibRegister comes to my mind. Or a long Sleep in a tight loop where AutoIt itself handles the "sleep" and maybe some more.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0