switch case question

Kay C Lan lan.kc.macmail at gmail.com
Fri Nov 3 19:40:34 EST 2006


OK, I've basically run your scripts but instead of using your exact
script and button method I've used Richard Gaskin's excellent
revBench, part of his free Devolution tools.

So this is what is in one field:

put random(6) into tRandomNo
if (tRandomNo = 1) then
    get 1
else if (tRandomNo = 2) then
    get 2
else if (tRandomNo = 3) then
    get 3
else if (tRandomNo = 4) then
    get 4
else if (tRandomNo = 5) then
   get 5
else if (tRandomNo = 6) then
   get 6
end if

and this is in the other field:

put random(6) into tRandomNo
switch (tRandomNo)
case (1)
get 1
break
case (2)
get 2
break
case (3)
get 3
break
case (4)
get 4
break
case (5)
get 5
break
case (6)
get 6
break
end switch

I then set it to 100,000 iterations. So really it is doing exactly
what you've stated. With my 1.25 PBook I get 27 ticks for Switch, but
only 17 ticks for If-then. I've run it several time and get a
variation betwen 25 - 28 ticks for Switch and 12 - 18 for If-then.
revBench also gives a % with If-Then being anywhere between 25-50%
faster.

I've also played around a little, changing the 'get 1', 'get 2' etc to
'add 1 to tones', 'add 1 to ttwos' etc, and got the same result.

Can't explain why, but if you, and others, are getting faster with
Switch, then maybe in 'real' situations it is quicker, which makes me
feel even better about using it more:-)



More information about the use-livecode mailing list