Hello, the fastest in order:
if (condition) command
if condition { command }
if (condition) { command }
Regarding what the help file says, it only means that it might fail, in reality there are only a few cases which fail, involving || and &&:
if (condition || condition) command
reports an 'ambiguous' format error whereas
if (condition && condition) command
reports an 'echo' unknown operator format, this is inconsistent but not much of a problem.
Does this mean that if ($nick == $me) will execute faster than if $nick == $me?
It depends on if you use { } or not, as said above.
In some cases, mIRC will guess correctly faster than it would perfectly understand otherwise because of the extra parsing of { }.
Basically this is just text processing, less text to process means it will be faster (not always true, but true 99% of the time).
For example for your next question, processing aliases isn't as complex as if statement, meaning parsing the extra { } is just slower, of course it's slower by some pico seconds, so you can only see the difference when benchmarking with 50000 iterations, which is nowhere close to a real case scenario, but still.
Any other speed improvement is based on the text processing story, the less you do with mIRC scripting, the faster it will be, always try to get mIRC to do the job internally, which is done in C.
For example, $iif doesn't have it's own function, it's just an internal alias which is calling /if and return the result based on what /if reports, this makes $iif significantly slower than /if:
alias testingiif1 {
$iif(1 == 2,noop 1,noop 2)
}
alias testingiif2 {
if (1 == 2) noop 1
else noop 2
}
/testingiif1 looks appealing because you have only one line, it looks great.
Let's try:
//var %a 50000,%t $ticks | while (%a) { dec %a | testingiif1 } | echo -a $calc($ticks - %t)
followed by
//var %a 50000,%t $ticks | while (%a) { dec %a | testingiif2 } | echo -a $calc($ticks - %t)
if you have an on text event with one $iif, changing it to /if isn't going to make the script faster, or by some pico seconds.. But if you have a while loop repeating an $iif statement in that on text event, it's a good idea to change that $iif to /if.
Speed improvement really depends on what you are trying to do, using COM object for socket is significantly faster than using mIRC's socket for example, using command which does a lot of stuff internally such as /filter, $hfind, are usually the way to go, a clear example is using $read's 'w' switch instead of looping on all line with $read itself and comparing with mirc scripting with if (expression iswm $read(,N)).
Edit:
@sakana, your benchmark is not fair because you're comparing two differents things at the same time ({} around aliases and around the if statement, () used etc)
It must be noted that mIRC doesn't accept that you don't use () if you don't use { } and if the condition doesn't involve the three elements: first operand, operator, second operand:
//if 1 == 1 echo -a ok -- works
//if 1 echo -a ok -- doesn't work
//if a !isnum echo -a ok -- doesn't works
all of the above works if you add { }, this even lead to quirk where mIRC does not parse the rest as you would expect:
//if 1 == 1 var -s %a ok -- doesn't work because with /var or /set etc, mIRC is supposed not to evaluate the variable name, otherwise it would never work, but in this case, although it validates the condition, it fails not to evaluate the variable:
//if 1 == 1 var -s % $+ a ok -- works.
With that in mind, you can benchmark all of these:
alias testingif {
var %a 50000,%t $ticks
while (%a) {
dec %a
if (1 == 1) && (1 == 1) noop
}
echo -a (condition) && (condition) command no bracket in $calc($ticks - %t)
%a = 50000
%t = $ticks
while (%a) {
dec %a
if (1) && (1) { noop }
}
echo -a (condition) && (condition) command ye bracket in $calc($ticks - %t)
%a = 50000
%t = $ticks
while (%a) {
dec %a
if (1 && 1) { noop }
}
echo -a (condition && condition) command ye bracket in $calc($ticks - %t)
%a = 50000
%t = $ticks
while (%a) {
dec %a
if 1 == 1 && 1 == 1 noop
}
echo -a condition && condition command no bracket in $calc($ticks - %t)
%a = 50000
%t = $ticks
while (%a) {
dec %a
if 1 == 1 && 1 == 1 { noop }
}
echo -a condition && condition command ye bracket in $calc($ticks - %t)
%a = 50000
%t = $ticks
while (%a) {
dec %a
if (1 == 1 && 1 == 1) { noop }
}
echo -a (condition && condition) command ye bracket in $calc($ticks - %t)
}
(condition) && (condition) command no bracket in 1373
(condition) && (condition) command ye bracket in 1248
(condition && condition) command ye bracket in 1232
condition && condition command no bracket in 1357
condition && condition command ye bracket in 1482
(condition && condition) command ye bracket in 1482
So when && is involed, the fastest seems to be using both () and { }, so with && involved, mIRC is slower to guess even though there is less text to process whereas it's the other way around when && isn't involved.Edit : The fastest seems to be if (condition && condition) { command }, not if (condition) && (condition) { command } like the above implied.
Edit2: well after running this a bit more, both the 2nd and 3rd are equivalent (sometimes equal, sometimes one is ahead, sometimes it's the other), i extended the benchmark to 100000 iterations with still the same result, but clearly you should not observe that "if (condition) && (condition) commands" is faster, it takes 300 more millisecond than the fastest here :\