From memory /IF is faster than $iif outright. However that said, $iif offers inline multichoices within commands, while an IF must have two copies of the command one for each choice.
Not so hard if there is just one IF, but what if its 6 A or B options etc.
In your examples the $iif isnt being put to the full use of its ability of course, but is a good example of where a layered IF would have speed advantages, although as I said /IF is faster anyway, so this maybe just the panning out of that speed.
I created the following test to see what might come out
alias testx {
var %max = 10000
var %x = 5
while (%x) {
var %ticks = $ticks
var %i = %max, %rtn
while (%i) {
%rtn = $iif(1 < %x, -i $v1 $iif(2 < %x,$v1 $iif(3 < %x,$v1 $iif(4 < %x,$v1))))
dec %i
}
var %m1 = $calc($ticks - %ticks)
;
var %ticks = $ticks
var %i = %max, %rtn
while (%i) {
if (1 < %x) {
%rtn = -i $v1
if (2 < %x) {
%rtn = %rtn $v1
if (3 < %x) {
%rtn = %rtn $v1
if (4 < %x) {
%rtn = %rtn $v1
}
}
}
}
dec %i
}
var %m2 = $calc($ticks - %ticks)
;
echo -a TEST %x : Method1 ticks %m1 : Method2 ticks %m2 ( $+ $calc(%m2 / %m1 * 100) $+ % $+ ) -- $calc(%m1 / %max) : $calc(%m2 / %max)
;
dec %x
}
}
results as follo0ws on my machine here
TEST 5 : Method1 ticks 2062 : Method2 ticks 1438 (69.738118%) -- 0.2062 : 0.1438
TEST 4 : Method1 ticks 2062 : Method2 ticks 1297 (62.900097%) -- 0.2062 : 0.1297
TEST 3 : Method1 ticks 1703 : Method2 ticks 1031 (60.540223%) -- 0.1703 : 0.1031
TEST 2 : Method1 ticks 1312 : Method2 ticks 766 (58.384146%) -- 0.1312 : 0.0766
TEST 1 : Method1 ticks 875 : Method2 ticks 500 (57.142857%) -- 0.0875 : 0.05
test 5 means all conditions were meet and progressing back to test1 meaning no conditions were meet (none becuase each condition relies apon the previous to be true to be checked)
The end two numbers are ticks for method1 and method2 per test
So at 10,000 occurances your saving between 0.375 and 0.624 seconds total, now this might be a significant saving if your calculating the gravity effects of a black hole on the movement of every particile within its displacement field, but is it this important in where you have it. (im not being smart here, I really dont know how time criticle or laggingly this code is)
* to me the choice of to use /IF or $iif comes down to what one makes the code easier to diagnose whats going wrong or right with it, if i have to come back to it.