This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X

# AutoIT Speed Tester

25 replies to this topic

### #1 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 19 August 2007 - 07:53 AM

Well maybe it's me (it surely is) but I like my AutoIT code when it's FAST.
So here's a little program I whipped up in about an hour.
Updated 19Aug2007 with more comments and more test results

It will execute commands of your choice through two loops, 20 packs of 9999 iterations to be precise.
Making two loops increased the reliability of the reading (since it seems the first iteration is really slow because of cache issues and what not).

For example, you could compare
`\$Val = \$Val +1`

to ...
`\$Val += 1`

(in this case, the obvious winner is \$Val += 1 but it isn't always so evident)

The code is as simple as can be, I guess if you don't get it than it's not for you

In any case, the results you get might make you change your programming habits!

If you do a lot of looping then I suggest you try out the commands in those loops and see what's better.

Good luck!

EDIT:
It's been brought to my attention by chris95219 that GetTickCount() cannot be properly timed.
Also if you use the \$i and \$j variables in your code (both loop counters) you will obviously get incorrect results!

TESTED BY YOURS TRUELY:
1. For/Next loops are champions. Try not to use While/Wend or Do/Until
2. If \$Val is faster than If \$Val = 1 or \$Val = TRUE
3. If \$Val = 1 is faster than \$Val = TRUE
4. If Not \$Val is faster than If \$Val = 0 or \$Val = FALSE
5. If \$Val = 0 is faster than If \$Val = FALSE
6. < and > are faster than =, >= or <= (Wow!)
7. \$i += 1 is faster than \$i = \$i + 1
\$i -= 1 is faster than \$i = \$i - 1
\$i *= 1 is faster than \$i = \$i * 1
\$i /= 1 is faster than \$i = \$i / 1
8. If doing a lot of verifications on a single variable:
Switch is fastest, Select is second (but slow) and If is slowest.
9. If \$Val is a string, If Not \$Val is faster than If \$Val = ""
If \$Val is faster than If \$Val <> ""
10. When doing binary operations, If \$Val -128 > 0 is twice as fast
as If BitAnd(\$Val, 128).
11. Using Hex numbers is faster than using decimal numbers
12 Replacing dec/hex numbers by variables slows down execution. Use hex/dec numbers when possible
13. Longer variable names = longer execution time. Keep variable names short and clear!
14. StringRegExpReplace() is slower than StringReplace(). Use it only if necessary!
15. StringRegExp() is slower than StringInStr(). Use only if necessary!
16. Opt("ExpandEnvStrings",1) makes \$Val = "%TEMP%" faster than \$Val = EnvGet("temp")
or \$Val = @TempDir
17. \$Val = @TempDir is faster than \$Val = EnvGet("temp")
18. Opt("ExpandVarStrings",1) makes \$Val = "\$String\$" slightly faster than \$Val = \$String
19. However \$Val = "@TempDir@" is slower than \$Val = @TempDir (go figure!)

Edited by Celeri, 21 August 2007 - 02:46 AM.

• Cahkhene25 likes this
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!)

### #2 cppman

cppman

Anonymous

• Active Members
• 1,626 posts

Posted 19 August 2007 - 08:29 AM

Nice test...

(but these results would be inaccurate if AutoIt uses GetTickCount() internally for it's Timer functions...)

### #3 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 19 August 2007 - 08:40 AM

Nice test...

(but these results would be inaccurate if AutoIt uses GetTickCount() internally for it's Timer functions...)

Wow, I've never used GetTickCount()
I'll add a line to the first post just in case

BTW there are other functions that can't really be tested by my program.
There's "Exit" (duh!) and "Return".
I guess you could call a function and return but you can never test "Return" all alone.

Which makes me think ... Hmmm what's fastest?

```SetError(\$ErrNum)
Return```

Or
`Return SetError(\$ErrNum)`

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!)

### #4 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 19 August 2007 - 08:49 AM

`SetError(\$ErrNum)<BR>Return`

Or
`Return SetError(\$ErrNum)`

On my computer Return SetError(\$ErrNum) is marginally slower than SetError(\$ErrNum)
Return

But by so little that there's nothing to write home about

Edited by Celeri, 19 August 2007 - 10:13 PM.

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!)

### #5 cppman

cppman

Anonymous

• Active Members
• 1,626 posts

Posted 19 August 2007 - 09:58 AM

It would be pretty cool if you used an input box or 'load file' to let the user choose the file/expression to test it's speed

### #6 Sunaj

Sunaj

Prodigy

• Active Members
• 190 posts

Posted 19 August 2007 - 10:07 AM

Hi Celeri, thanks for sharing your experiments here, there has been a few other threads dealing with the differing performance of various AutoIt loops and operators - still you added quite a few subtle ones I haven't come across before ("If Not \$Val" being faster than "If \$Val = 0" for an example).

Sunaj

EDIT: Interesting thing here is that learning these basic tricks of the trade is a rather good idea since they hold true (on some level at least) not just for AutoIt but also for Java, C++ and more (see: http://www.codeproject.com/cpp/C___Code_Optimization.asp and http://www.javaworld.com/javaworld/jw-04-1...ze.html?page=1)

TESTED BY YOURS TRUELY:
1. For/next loops are champions. Try not to use While/Wend or Do/Until
2. If \$Val is faster than If \$Val = 1 or \$Val = TRUE
3. If \$Val = 1 is faster than \$Val = TRUE
4. If Not \$Val is faster than If \$Val = 0 or \$Val = FALSE
5. If \$Val = 0 is faster than If \$Val = FALSE
6. < and > are faster than =, >= or <= (Wow!)
7. \$i += 1 is faster than \$i = \$i + 1
8. If doing a lot of verifications on a single variable:
Switch is fastest, Select is second (but slow) and If is slowest.

Edited by Sunaj, 19 August 2007 - 10:18 AM.

### #7 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 19 August 2007 - 10:57 AM

It would be pretty cool if you used an input box or 'load file' to let the user choose the file/expression to test it's speed

I'll see what I can do
However this might require a thinking cap! --> it implies a self-modifying code. But I'm all for it if it is possible.

One way this could be done is by #including a file which contains bunch of UDFs to be speedtested. The user would then have to specify which UDF to speed test. (i.e.: _speedtest1() )

EDIT:
In retrospect, it can be done with Execute() but since you're going to have to code it anyways, an input box or an input file is in my opinion not the best way to go. Don't forget this program tests code snippets that sometimes requires preset variables and/or calling parameters, which is way beyond Execute() (I was lead to believe it is used to return the result of a simple expression like 1 + \$B [the function returns the equal part of the formula and \$B in this case must be previously declared]). In any case if it's what you want it's easy to add two lines to the code:

Put this at the start:
`\$Input_CODE = InputBox("AutoIT Speed Test","Enter command to test it's speed"&@CR&"(One line only!)")`

Put this line at line after the "For \$j = 1 To 9999" and the comments that follow
`\$Result = Execute(\$Input_CODE)`

You can ConsoleWrite the variable \$Result after the loops if you want to see what happened.

There are also issues with syntax checking but if it's used by someone who knows his stuff than I guess it's OK. In any case I commented every line so that unexperimented users can take a peek and understand how this works. If any of you modifies the code (make it faster?) than I'd really appreciate seeing what you did

Edited by Celeri, 19 August 2007 - 06:10 PM.

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!)

### #8 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 19 August 2007 - 11:01 AM

Hi Celeri, thanks for sharing your experiments here, there has been a few other threads dealing with the differing performance of various AutoIt loops and operators - still you added quite a few subtle ones I haven't come across before ("If Not \$Val" being faster than "If \$Val = 0" for an example).
EDIT: Interesting thing here is that learning these basic tricks of the trade is a rather good idea since they hold true (on some level at least) not just for AutoIt but also for Java, C++

Thanks! I started learning C++ but I'm lazy and I have a limited amount of time.
AutoIt's learning curve is really, really low
Although there's a few quirks here and there but you get used to it.

I'll keep on comparing - if any of you has anything interesting, post it and I'll add it to the first post
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!)

### #9 laffo16

laffo16

Prodigy

• Active Members
• 188 posts

Posted 20 August 2007 - 09:58 PM

i would like to see differences in speed/performance between autoit & c# at handling large _arrays (sorting and searching).

### #10 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 20 August 2007 - 11:33 PM

i would like to see differences in speed/performance between autoit & c# at handling large _arrays (sorting and searching).

Since AutoIt is an interpreted language (as compared to a compiled language) the difference will probably pretty big (not in favor of AutoIT3). Hey anyone here can prove me wrong?
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!)

### #11 cppman

cppman

Anonymous

• Active Members
• 1,626 posts

Posted 21 August 2007 - 12:25 AM

Since AutoIt is an interpreted language (as compared to a compiled language) the difference will probably pretty big (not in favor of AutoIT3). Hey anyone here can prove me wrong?

C# is much much much faster than AutoIt. In fact C# is probably about 90% the speed of C++.

Edited by chris95219, 21 August 2007 - 12:35 AM.

### #12 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 21 August 2007 - 03:02 AM

C# is much much much faster than AutoIt. In fact C# is probably about 90% the speed of C++.

Mind you, it depends.
If you're working with files and file transfers in AutoIT3, the difference in speed with C# or C++ will be minimal since the program will be dependent upon Harddrive latency. I once made a cleaning program in AutoIT3 and it was up there with CCleaner in terms of speed

Edited by Celeri, 21 August 2007 - 03:03 AM.

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!)

### #13 cppman

cppman

Anonymous

• Active Members
• 1,626 posts

Posted 21 August 2007 - 05:52 AM

The thing is, you have to remember what AutoIt is doing behind the scenes. Your AutoIt program is being overlayed on a C++ program.

```\$x = TimerInit()
for \$i = 0 to 1000
random(0, 65535)
Next
\$y = TimerDiff(\$x)
MsgBox(0, "", \$y)```

This is taking anywhere from 9 to 60 ms on my computer - that is very slow. Whereas you can do that in C# or C++ in much much less time.

### #14 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 21 August 2007 - 02:28 PM

The thing is, you have to remember what AutoIt is doing behind the scenes. Your AutoIt program is being overlayed on a C++ program.

```\$x = TimerInit()
for \$i = 0 to 1000
random(0, 65535)
Next
\$y = TimerDiff(\$x)
MsgBox(0, "", \$y)```

This is taking anywhere from 9 to 60 ms on my computer - that is very slow. Whereas you can do that in C# or C++ in much much less time.

That much is clear
However my mom can program AutoIT3, but I doubt she'd get along with C++ or C# ahahahah
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!)

### #15 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 29 August 2007 - 11:23 PM

That much is clear
However my mom can program AutoIT3, but I doubt she'd get along with C++ or C# ahahahah

Ok so it looks I'm going to have to reply to myself to get any input here

So anyways, just discovered 3.2.6.0 is out and it boasts a 30%-40% speed increase ... we'll be the judge of that

<LI>Changed: General performance improvements (currently around 30-40% over 3.2.4.9)

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

I'll keep you posted with some observations in the following days.

See ya!

Edited by Celeri, 29 August 2007 - 11:25 PM.

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!)

### #16 sandman

sandman

I ❤ WordPress

• Active Members
• 1,303 posts

Posted 29 August 2007 - 11:41 PM

I think this is a really good idea for testing AutoIt's limits. This will help a lot of people!

Edited by sandman, 29 August 2007 - 11:41 PM.

"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();

### #17 Celeri

Celeri

Prodigy

• Active Members
• 157 posts

Posted 30 August 2007 - 01:53 AM

Tested and so far it's true - 3.2.6.0 is very much FASTER.
I suggest you upgrade and test again

P.S.: Thanks for the encouragement Sandman Where do I apply for the toaster?

Edited by Celeri, 30 August 2007 - 01:54 AM.

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!)

### #18 Qwerty212

Qwerty212

• Active Members
• 106 posts

Posted 18 March 2012 - 07:19 PM

1. For/next loops are champions. Try not to use While/Wend or Do/Until

But how can we change a While statement like when you want to get gui msg like this one:
```While 1
\$msg = GUIGetMsg()

Select
Case \$msg = \$Button1
Func1()
Endselect
Wend```

and subtitute it for a For/Next ???

### #19 Shaggi

Shaggi

Universalist

• Active Members
• 309 posts

Posted 18 March 2012 - 09:22 PM

But how can we change a While statement like when you want to get gui msg like this one:

```While 1
\$msg = GUIGetMsg()

Select
Case \$msg = \$Button1
Func1()
Endselect
Wend```

and subtitute it for a For/Next ???

You shouldn't worry about that. A msgloop doesn't run that often for a change to be significant.
@OP
Autoit doesn't use getickcount, but queryperformancecounter, last time i checked, which is high-resolution and ok for testing.
Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

### #20 BrewManNH

BrewManNH

באָבקעס מיט קודוצ׳ה

• MVPs
• 10,597 posts

Posted 18 March 2012 - 11:55 PM

@OP
Autoit doesn't use getickcount, but queryperformancecounter, last time i checked, which is high-resolution and ok for testing.

I don't think the OP will be too concerned, he hasn't been online in nearly 3 years, as this is a 5 year old topic brought back from the dead.

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 an XP machine, 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!

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

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.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users