Edit menu recipe?
Richard Gaskin
ambassador at fourthworld.com
Fri Aug 20 20:31:41 EDT 2004
J. Landman Gay wrote:
> On 8/20/04 11:04 AM, Richard Gaskin wrote:
>
>> If one's picky about minimizing typing, because most of those are
>> handled by the engine you can use the case block's fall-through
>> feature to trim the code -- this version also handles "Select All" for
>> objects:
>>
>> on menuPick which
>> switch which
>> case "Cut"
>> case "Copy"
>> case "Paste"
>> case "Undo"
>> do which
>
>
> Picky purist point: using "do" forces the compiler to run and can slow
> the script, which is why I use the redundant form.
Yes, in older, slower xTalks one might get a noticeable difference
between "do" and the natural message path.
But it's a whole other world with Transcript -- this script tests timing
of both the natural message path and the "do" command:
-------------------------
on mouseUp
put 1000 into n
-- test 1: natural message flow
put the millisecs into s
repeat n
DoSomething
end repeat
put the millisecs - s into s1
--
-- test 2: do:
put the millisecs into s
repeat n
do "SomethingElse"
end repeat
put the millisecs - s into s2
--
put "Natural: "& (s1/n) &"ms/iteration Do: "&(s2/n)&"ms/iteration"
end mouseUp
on DoSomething
get 1+1
end DoSomething
on SomethingElse
get 1+1
end SomethingElse
--------------------------
When I run it on my PBG4 1GH I get:
Natural: 0.013ms/iteration Do: 0.016ms/iteration
So yes, using the do command is slower, but only by about 0.003ms.
Given that the menu script is responding to a user action and no user
will be faster than 0.003ms, there's no perceptable savings to the
system's performance, but using do can offer immediate savings for
developer productivity.
While curmudgeonly, there is a practical point here:
With Transcript you can often make choices that put your productivity as
a developer over concerns about "fast" or "slow". Those terms are
relative, and as we've seen with accessing custom properties vs. globals
the actual differences are often very small, imperceptable at even
10,000 iterations or more.
When in doubt benchmark, and consider whether the script in question
will be responding to a direct user action....
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list