Switch or If
Mark Smith
lists at futilism.com
Thu Apr 23 06:33:59 EDT 2009
On 23 Apr 2009, at 11:02, <camm29 at tesco.net> <camm29 at tesco.net> wrote:
> All ,
>
> Which is faster in a loop ?
>
> SWITCH or IF
>
>
This is a little test I did. I get about 35ms for 'switch', about
20ms for 'if'. As Jim said though, I suspect it'll vary according to
the kind and complexity of conditions you're testing.
on mouseUp
put the millisecs into tStart
repeat 10000
put random(5) into tSw
switchTest tSw
end repeat
put the millisecs - tStart into t1
put the millisecs into tStart
repeat 10000
put random(5) into tIf
ifTest tIf
end repeat
put the millisecs - tStart into t2
put t1 && t2
end mouseUp
-----
on switchTest pSw
switch pSw
case 1
break
case 2
break
case 3
break
case 4
break
default
break
end switch
end switchTest
-----
on ifTest pIf
if pIf = 1 then
else if pIf = 2 then
else if pIf = 3 then
else if pIf = 4 then
else
end if
end ifTest
Best,
Mark
More information about the use-livecode
mailing list