Re: Since Apple Listens to this List... [next repeats]
Re: Since Apple Listens to this List... [next repeats]
- Subject: Re: Since Apple Listens to this List... [next repeats]
- From: has <email@hidden>
- Date: Tue, 12 Feb 2002 13:47:55 +0000
Matthew Smith wrote:
>
>> I thought I'd say "I'd love to see a case statement included in a
>
>>near-future
>
>> revision"; it would be so much more elegant than If/else
>
>>if/elseif/elseif/etc
>
>
>
> "next repeat" would be very elegant, too.
>
>
Why not throw an error and catch it before then end of the repeat?
Well, I did a quick, and now obviously TOTALLY UNRELIABLE speed test here
(yeah, thanks a LOT, Nigel...;p), and got the following results:
======================================================================
set x to false
set a to the ticks
repeat 1000 times
--normal method
repeat 100 times
if not x then
--do stuff
end if
end repeat
end repeat
set b to the ticks
repeat 1000 times
--double loop kludge
repeat 100 times
repeat 1 times
if not x then exit repeat
--do stuff
end repeat
end repeat
end repeat
set c to the ticks
repeat 1000 times
--deliberate error kludge
repeat 100 times
try
if not x then error
--do stuff
on error
end try
end repeat
end repeat
set d to the ticks
{b - a, c - b, d - c}
--> {27, 74, 46} --without early break (x is true)
--> {26, 49, 639} --with early break (x is false)
======================================================================
For us hard-as-nails coders who ain't afraid of a few dozen nested IF
statements (hey, it can always be refactored it later, right?), the old
school approach is fastest.
For those gentle souls who don't mind a slight speed hit, the
double-repeat-loop method is not too bad; bit of a hit, but probably
trivial in most cases.
As far as throwing deliberate errors goes, however, it's probably the least
practical solution being *25* times slower when invoked. (A good reminder
that throwing errors for non-fatal purposes is far from a free lunch.)
Also, I think someone mentioned a few weeks ago that it also leaks memory,
which would be another reason to avoid using it if you don't have to.
HTH
has
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.