I was wondering how much "Loop" slows things down. So I tested it in comparison with simple math funcs. Maybe somebody will find this useful in optimizing their scripts.
First test, 30 additions of 1 var:
Code: Select all
t := A_TickCount
Loop 100000
Loop 30
a%a_index%++
t := A_TickCount - t
tt := A_TickCount
Loop 100000
a1++ , a2++ , a3++ , a4++ , a5++ , a6++ , a7++ , a8++ , a9++ , a10++ , a11++ , a12++ , a13++ , a14++ , a15++ , a16++ , a17++ , a18++ , a19++ , a20++ , a21++ , a22++ , a23++ , a24++ , a25++ , a26++ , a27++ , a28++ , a29++ , a30++
tt := A_TickCount - tt
msgbox % "Time in milisec:`n" t "`n" tt "`n`nSpeed difference = " Round(t/tt,1)
Second test, 30 additions of 4 vars:
Code: Select all
t := A_TickCount
Loop 30000
Loop 30
a%a_index%++ , b%a_index%++ , c%a_index%++ , d%a_index%++
t := A_TickCount - t
tt := A_TickCount
Loop 30000
a1++ , b1++ , c1++ , d1++ , a2++ , b2++ , c2++ , d2++ , a3++ , b3++ , c3++ , d3++ , a4++ , b4++ , c4++ , d4++ , a5++ , b5++ , c5++ , d5++ , a6++ , b6++ , c6++ , d6++ , a7++ , b7++ , c7++ , d7++ , a8++ , b8++ , c8++ , d8++ , a9++ , b9++ , c9++ , d9++ , a10++ , b10++ , c10++ , d10++ , a11++ , b11++ , c11++ , d11++ , a12++ , b12++ , c12++ , d12++ , a13++ , b13++ , c13++ , d13++ , a14++ , b14++ , c14++ , d14++ , a15++ , b15++ , c15++ , d15++ , a16++ , b16++ , c16++ , d16++ , a17++ , b17++ , c17++ , d17++ , a18++ , b18++ , c18++ , d18++ , a19++ , b19++ , c19++ , d19++ , a20++ , b20++ , c20++ , d20++ , a21++ , b21++ , c21++ , d21++ , a22++ , b22++ , c22++ , d22++ , a23++ , b23++ , c23++ , d23++ , a24++ , b24++ , c24++ , d24++ , a25++ , b25++ , c25++ , d25++ , a26++ , b26++ , c26++ , d26++ , a27++ , b27++ , c27++ , d27++ , a28++ , b28++ , c28++ , d28++ , a29++ , b29++ , c29++ , d29++ , a30++ , b30++ , c30++ , d30++
tt := A_TickCount - tt
msgbox % "Time in milisec:`n" t "`n" tt "`n`nSpeed difference = " Round(t/tt,1)
In first test, speed difference came to be ~3.5, in second ~5, which means that loop (inner one) + resolving var references (a%a_index%>a[1,2..]) consumed 3.5-5 times more time than actual calculations! Clearly this difference is getting less as complexity of calculation increases. Still, in some situations where Loop has only calculations inside without "if/break/continue...", and performance matters (as it does in my project), replacing Loop like in example above speeds things a lot.
Obviously, no need to rewrite things manually, in the example above I used this:
Code: Select all
q := ""
Loop 30
q .= "a" a_index "++ , b" a_index "++ , c" a_index "++ , d" a_index "++ , "
clipboard := q