Sign in to follow this  
Followers 0
Celeri

AutoIT Speed tester

19 posts in this topic

#1 ·  Posted (edited)

I'm really disappointed by my latest project. My initial versions were really quick but my latest ones just CRAWL :whistle:

So I set up this little program to test the speed of different commands in AutoIT. It isn't pretty but I think the logic is there.

It tests a specific function 1000 times, 15 times in a row and then averages the results. It also copies the average to the clipboard so you can paste it in excel or AutoIT (remove the semicolon on line 25 if you want to paste in Excel)

Anyways, what I really wanted to know is how For/Next, Do/Until and While/Wend compared. I've pasted the results within the code for my program. (And I've run the program 5 times just to be sure eheheh)

; Speed Test 1.00
; Standard 1000 iterations for each command
; Repeat each 1000 iterations 15 times and calculate average
; Copy value to clipboard to paste here or in another program

#include<array.au3>
Dim $Stat[16]
$Total = 0

For $a = 1 to 15
    $i = 0
    $Start = TimerInit()
; ==== CODE STARTS HERE
    For $i = 1 to 1000
    Next
; ==== CODE ENDS HERE
    $End = TimerDiff($Start)
    $Stat[$a] = $End
Next
_ArrayDisplay($Stat,"TimerDiff")

For $i = 1 to Ubound($Stat)-1
    $Total=$Total+$Stat[$i]
Next
MsgBox(1,"Average",$Total/(Ubound($Stat)-1))
ClipPut("; "&$Total/(Ubound($Stat)-1)&@CR)
Exit

; For/Next THE WINNER!
; 7.57139979276093
; 7.79678943795334
; 7.93297816843535
; 7.68593630376008
; 7.67898507640452

; Do/Until
; 14.9826625695263
; 14.9933205178595
; 14.6738275151559
; 15.0026756946678
; 14.966137730613

; While/Wend
; 19.7842360381606
; 19.3168873881921
; 19.6748217386644
; 19.7558880432582
; 19.7558880432582


; If/EndIf THE WINNER!
; 0.0220238920451162
; 0.0221127666416551
; 0.0219136742058813
; 0.0218826598063387
; 0.0221396124391086

; Select/EndSelect
; 0.0221819654363335
; 0.0232866449899358
; 0.02282909922464
; 0.0245067114493634
; 0.0224139064565691

; Compared commands
; Loops types
; For/Next
    For $i = 1 to 1000
    Next
; Do/Until
    Do
        $i=$i+1
    Until $i=999
; While/Wend
    While $i < 999
        $i=$i+1
    WEnd
    
; If/Then types
; If/Then
    If 1 Then
    EndIf
; Select/EndSelect
    Select
        Case 1
    EndSelect

Notice how For/Next loops simply dominate the two other loops?

It seems clear (at least to me) that AutoIT3 looses a lot of time with "$i = $i +1" and that translates in really poor performance. It gets even worse with While/Wend because the loop checks if a variable is smaller than 999 (I assume = is faster to process than <).

So what's the moral of the story? There's a few ways of writing the same stuff in AutoIT3. Not all of them give quick results.

Please note, the values I got are NOT from compiled code and my PC is a P4 2800Mhz 800Mhz FSB, 512Mb Ram Dual-Channel (Asus P4P800 SE / Intel 865Pe chipset).

Hope this comes in handy :dance:

Edited by Celeri

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites



Here's the values for the compiled version of this program ...

(using the following lines:)

; ==== CODE STARTS HERE
    For $i = 1 to 1000
    Next
; ==== CODE ENDS HERE

; 4.90730872667072

; 4.90685701694834

; 5.15343650027989

; 4.93482150045855

; 4.91766653565346

And now values for the following lines:

; ==== CODE STARTS HERE
    Do
        $i=$i+1
    Until $i=999
; ==== CODE ENDS HERE

; 11.4218521694596

; 11.5570175915008

; 11.7162947082574

; 11.520992365503

; 11.5550718547897

So For/Next is still :whistle:


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

It interests me that your compiled script yields faster results than an uncompiled copy, since a 'compiled script' is really just an AutoIt executable 'stub' with an encoded form of the original script found at the end.

I suppose that the differences in speed are due to the compiled executable's AutoIt stub not having to parse human-readable tokens into AutoIt-usable bytecode. Nonetheless, I would have thought that an uncompiled AutoIt script would be completely translated to bytecode before execution of it were to start and not on a line-by-line basis (the results shown above suggest otherwise).

Perhaps it does though, with the speed differences being caused by other factors.

Share this post


Link to post
Share on other sites

I suppose that the differences in speed are due to the compiled executable's AutoIt stub not having to parse human-readable tokens into AutoIt-usable bytecode. Nonetheless, I would have thought that an uncompiled AutoIt script would be completely translated to bytecode before execution of it were to start and not on a line-by-line basis (the results shown above suggest otherwise).

<{POST_SNAPBACK}>

Yep, I was a bit surprised too :dance:

By the way tried to see if using Hex values made any difference in speed with regular numbers. It made the loop even slower! (showing that using Hex numbers probably ADD to the processing each time they're handled)

Which is kind of sad; perhaps AutoIT4 will enable the user to configure a variable to be of a certain type (bolean, floating point, etc. etc. etc.) with the economy in speed when precision is not needed ... Oh well :whistle:

BTW I am grateful, AutoIT is a lot of fun to program - anyways my wife hates it so it must be doing something good :dance:


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

A bit more info ...

I've compared two similar forced loops:

While 1
        $Fichier = FileFindNextFile($Recherche)
        If @error Then ExitLoop
    Wend

and

Do
        $Fichier = FileFindNextFile($Recherche)
        If @error Then ExitLoop
    Until 0

Note that a previous search was started BEFORE THE LOOP with FileFindFirstFile :dance:

Now I've never seen anyone use Do/Until 0 but trust me, it does exactly the same thing. It loops forever :whistle:

Here are the results (in miliseconds, repeated 5 times to reduce statistical errors):

; While/Wend

; 61.762602327271

; 61.9402332987935

; 61.8511987946785

; 61.8864561641715

; 61.9275730875049

; Do/Until

; 46.7085407748836

; 46.5693268064935

; 46.72530339086

; 46.6055034361192

; 46.5999905432284

As you can see, there's a clear 15Ms between the two variations!

At this moment I'm wondering why there is such a discrepancy.

There should be little difference between both variations.

Anyways, I've modified all my While/Wend loops .... :dance:


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

you could use While NOT @error.

<{POST_SNAPBACK}>

I've taught of that :whistle: (thanks anyways!)

My problem is that the error flag will be overwritten as soon as you add material to the loop. So by the time you get to "While NOT @error", it's not checking for the same error :dance:

And loading the next file at the end of the procedure is not very efficient :dance:

Oh btw I don't know why but in my previous test the For/Next loop gave me wrong results. Testing it again puts back For/Next on top, with a large margin:

For $i = 1 to 1000
        $Fichier = FileFindNextFile($Recherche)
        If @error Then ExitLoop
    Next

Results (in miliseconds, repeated 5 times to reduce statistical errors):

; 27.5826528983695

; 27.6469020616715

; 27.5852736151308

; 27.5871114684199

; 27.5142494729696

So it's clear. Until something is done about Do/Until and While/Wend, anyone making time-critical loops should stick to For/Next.

Too bad, Do/Until and While/Wend really make a program easy to read.


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

So it's clear. Until something is done about Do/Until and While/Wend, anyone making time-critical loops should stick to For/Next.

Too bad, Do/Until and While/Wend really make a program easy to read.

This is not so strange. In a For/Next loop autoit knows how many itterations to do upfront. This is not the case with a Do/Until While/Wend loop. Also in your Do/Until While/Wend loops autoit has to do "real work" namely
$i=$i+1

And sa a last note. When testing like this, Im my opinion, each test should run in it's own process. Aka. One test -> one script/program. When isolated like this startup, interpreter, compilation or what ever should not affect the result (on a unloaded machine).

Regards

Uten

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

also just an FYI,

[$i+=1] is faster then [$i=$i+1]

WOW ... this is GREAT!

EDIT: Works only on beta versions ...

Although the "wording" is a bit weird... I did try [$i==+1] --> Syntax error

I might also try my speed test on the latest beta version (just for kicks). This might seem strange but I had a real tough time getting the betas to work ... ;)

I must be stooopid or something :P

Edited by Celeri

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

The += is a C-style operator that just adds the number to the variable, instead of getting the value, adding to it, and setting the variable to the new value.

Example1:

You think of a number. Add 2 to the number.

Example2:

You think of a number. Tell me the number. I add 2 to the number, I tell you the new number.

Which is faster?


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

While 1
        $Fichier = FileFindNextFile($Recherche)
        If @error Then ExitLoop
    Wend
Would "While True" make it faster so it dosn't have to see if 1 is true everytime or does it have to evaluate if true is true?

----------

This is not so strange. In a For/Next loop autoit knows how many itterations to do upfront.

But if it knew then when you change the variable in the for loop it wouldnt change how many times it would loop.

for $i = 1 to 7
$i = 2
Next
Would still be a loop of 7

-------

[edit]

Oooo... Mabey

For $i = 1 To 7
$i = 2
Next
Is a faster
While 1
WEnd
Edited by gamerman2360

Share this post


Link to post
Share on other sites

also just an FYI,

[$i+=1] is faster then [$i=$i+1]

Didn't seem to want to work for me using latest beta and scite (Au3Check complained).

Instead of:

Do
 $x = $x + 1
...
Until 0

I tried:

Do
 $x+ = 1
...
Until 0

Is this the correct syntax or am I doing something wrong?

Share this post


Link to post
Share on other sites

Have you tried saving it and running the script by itself? I think scite has its function names set to the stable one, it can be switched, however, if you look at some of scite's files. Anyway if it is set to the stable definations then the check will have errors.

Share this post


Link to post
Share on other sites

No, I didn't think to run it outside of sciTE because I assumed Au3Check to be correct in that it was a syntax error. I'll try it tonight. Thanks for the heads up.

Not sure about switching in sciTE, but I normally run scripts as beta. To be honest, sciTE has so many tools and options that it just confuses me so I tend to manually type in the code and only use ALT-T and ALT-F5.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Do
 $x+ = 1
...
Until 0

Is this the correct syntax or am I doing something wrong?

This is right:

Do
$x += 1
...
Until 0

Download latest beta and

look into Help file...

Edited by Zedna

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

So it works now? I wasn't that sure if scite specified which version of Autoit, lol. I know there is a way to update the definations, for my the updater is here: "C:\Program Files\AutoIt3\SciTe\Defs"

Edited by gamerman2360

Share this post


Link to post
Share on other sites

This is right:

Do
$x += 1
...
Until 0
Ah, never really used it till now... Cool.

Share this post


Link to post
Share on other sites

Cool, $x += 1 works without syntax error popping up.

Thanks Zedna

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