So here's a little program I whipped up in about an hour.
AutoIT_Speed.au3 4.08KB 1223 downloads
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
$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.
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.