Sam_ wrote:lexikos wrote:Unless it is embedded within another expression, vName += 1 is literally a call to EnvAdd.
mean that using EnvAdd would be faster than using vName += 1?
lexikos wrote:
No.
By "x is literally y", I mean that x and y are the same thing. That thing can't be faster than itself.
You stated that
vName += 1 calls the command EnvAdd. That implies that using EnvAdd directly might be slightly faster than using +=, as it presumably involves one less layer of interpretation before the underlying AHK source code to perform the addition is called.
lexikos wrote:
Look:
Code: Select all
a += 1
EnvAdd b, 2
c++
++d
ListLines
Pause
Result:
Code: Select all
001: a += 1
002: b += 2
003: c += 1
004: d += 1
This on the other hand implies the different syntaxes all get translated into/interpreted as +=. One would think, then, that using += directly would be the fastest, but
previous analysis indicates otherwise:
jNizM wrote:100.000.000 Loops
Code: Select all
A + B 7.822086
A - B 7.793425
A + 1 7.647965
A - 1 7.629782
A++ 6.906725
A-- 6.837371
++A 7.220017
--A 7.273083
My current round of testing supports these previous findings:
Code: Select all
Results:=""
Loop, 1000
{
A:=1
tic:=QPC(1)
Loop, 1000000
A:=A+1
toc:=(QPC(1)-tic)
Results.="A=A+1 " toc "`r`n"
A:=1
tic:=QPC(1)
Loop, 1000000
A+=1
toc:=(QPC(1)-tic)
Results.="A+=1 " toc "`r`n"
A:=1
tic:=QPC(1)
Loop, 1000000
A++
toc:=(QPC(1)-tic)
Results.="A++ " toc "`r`n"
A:=1
tic:=QPC(1)
Loop, 1000000
++A
toc:=(QPC(1)-tic)
Results.="++A " toc "`r`n"
A:=1
tic:=QPC(1)
Loop, 1000000
EnvAdd, A, 1
toc:=(QPC(1)-tic)
Results.="EnvAdd, A, 1 " toc "`r`n"
}
FileAppend, %Results%, %A_ScriptDir%\BenchResults.txt
ExitApp
QPC(R:=0){ ; By SKAN, http://goo.gl/nf7O4G, CD:01/Sep/2014 | MD:01/Sep/2014
Static P:=0, F:=0, Q:=DllCall("QueryPerformanceFrequency","Int64P",F)
Return !DllCall("QueryPerformanceCounter","Int64P",Q)+(R?(P:=Q)/F:(Q-P)/F)
}
which after some averaging shows:
Code: Select all
A++ 0.143022241
++A 0.14322938
EnvAdd, A, 1 0.143281911
A+=1 0.144320881
A=A+1 0.196662157
This is getting a bit OT, tho.