Switch or If
Phil Davis
revdev at pdslabs.net
Thu Apr 23 11:29:58 EDT 2009
Hi Camm,
Unless you're building something where the small difference in speed is
absolutely critical, I would seek to answer a different question: Which
structure will be easier to understand and maintain in the future when I
(or others) come back to it?
My 2 cents' worth -
Phil Davis
Mark Smith wrote:
>
> 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
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list