Sign in to follow this  
Followers 0
Raik

[Info] Speedtest for different Loops

16 posts in this topic

For Your Information:

The Loops need different Time to run. If Speed is important, have a Look at this Test.

$rounds=300000
$txt="AutoIt"
For $i=1 To $rounds-1
$txt&=",AutoIt"
Next
$array=StringSplit($txt,",")
; -------------------------
$begin = TimerInit()
For $i=0 To $rounds
;
Next
$time1 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
$i=$rounds
While $i
;
$i-=1
WEnd
$time2 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
$i=$rounds
Do
;
$i-=1
Until Not $i
$time3 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
$i=$rounds
Do
;
$i-=1
Until $i=0
$time4 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
$i=0
Do
;
$i+=1
Until $i=$rounds
$time5 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
$i=0
While $i<$rounds
;
$i+=1
WEnd
$time6 = Round(TimerDiff($begin),2)
; -------------------------
$begin = TimerInit()
For $i In $array
;
Next
$time7 = Round(TimerDiff($begin),2)


MsgBox(0,"Speedtest","For To:"&@tab&$time1&@CRLF&"While -:"&@tab&$time2&@CRLF&"Until Not:"&@tab&$time3&@CRLF& _
"Until =0:"&@tab&$time4&@CRLF&"Until +:"&@tab&$time5&@CRLF&"While +:"&@tab&$time6&@CRLF&"For In:"&@tab&$time7)

"Until" and "While", counting upwards, and "For In" ar slow. The fastest is "For To" in this Test


AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Share this post


Link to post
Share on other sites



I'd guess that subtraction is taking an awfully long time to finish by these tests.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Why guessing? try it.

and the substracting loops run faster, because they need no comparing ($i to $rounds) but finish by treating 0 as false.

Edited by Raik

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Share this post


Link to post
Share on other sites

I wasn't guessing, I used this demo and saw the results, "I'm guessing" is a figure of speech, probably doesn't translate that well though. ;) Subtraction takes longer on my computer than adding up does.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ahh, i'm not a native Speaker. ;)

My Results:

For To:     25.07
While -:   208.29
Until Not: 278.1
Until =0:  336.88
Until +:   370.97
While +:   398.33
For In:    403.56
Edited by Raik

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Share this post


Link to post
Share on other sites

Test this part to dispel mystification about ForTo speed, please:

For $i=0 To $rounds
$i-=0
Next

The point of world view

Share this post


Link to post
Share on other sites

You didnt catch the point. This test is not a question of "equity". "$i-=0" is a senseless operation and not necessary for the "For To" loop, while "$i-=1" is necessary for the "while -" loop to run.

And btw. even with this sesnseless operation "For To" is the fastest loop on my computer.


AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Share this post


Link to post
Share on other sites

Doesn't AutoIt add a 10ms sleep to While loops?


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

It will sleep the script if you're using GUIGetMsg, it doesn't normally sleep a while loop.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It will sleep the script if you're using GUIGetMsg, it doesn't normally sleep a while loop.

Ah, that's what I was thinking of.

Anyway, I'm doubting these benchmarks. Each benchmark should be ran in it's own compiled script for more accuracy.


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

Compiling the script shouldn't affect the speed much if at all. A compiled script is just the script and the interpreter stuck together.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Compiling the script shouldn't affect the speed much if at all. A compiled script is just the script and the interpreter stuck together.

It affected the speed greatly in a positive way when running on WINE so I concluded that it should logically be faster when running on normal Windows. Then again, WINE is not an emulator... that would be illegal (I think)


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

I just tested this for myself, compiling a script and running it, and then running AutoIt3.exe and running the script itself, the speeds are about the same. If you run this from SciTe it's slower than running the exe or AutoIt.exe and the script alone.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I just tested this for myself, compiling a script and running it, and then running AutoIt3.exe and running the script itself, the speeds are about the same. If you run this from SciTe it's slower than running the exe or AutoIt.exe and the script alone.

Ah, and WINE probably increased the slowness of running the script from SciTe.


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

Hi,

I believe the script is tokenised in the "compile" process which could well explain the slight speed increase I see with compiled scripts. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

The Devs probably know best.


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

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