Jump to content

Looping Question


Recommended Posts

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?

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...