Re: Passing *possible* variables to a handler
Re: Passing *possible* variables to a handler
- Subject: Re: Passing *possible* variables to a handler
- From: Nigel Garvey <email@hidden>
- Date: Tue, 16 Jul 2002 23:52:23 +0100
Paul Berkowitz wrote on Tue, 16 Jul 2002 08:44:11 -0700:
>
On 7/16/02 7:40 AM, "Arthur J. Knapp" <email@hidden> wrote:
>
>
> Nigel Garvey did some tests, (off list), in which he showed that
>
> repeatedly creating a script object inside a handler like this:
>
>
>
> on theHandler( theValue )
>
>
>
> script obj
>
>
>
> property aProperty : theValue
>
>
>
> end script
>
>
>
> -- stuff
>
>
>
> end theHandler
>
>
>
> did not seem to take up any excessive amount of time, ie: there does not
>
> appear to be any major reason to create objects outside of the context
>
> of where they are needed.
>
>
Ah, that was what I was asking the other day. Nigel, are these off-list
>
tests significantly different from your on-list test? Would you care to on
>
your offs?
It's difficult to reconstruct the details now. It dates from some private
correspondence Arthur and I had back in April, when we discovered we'd
developed remarkably similar techniques for case-insensitive offset
handlers. While discussing related matters, I asked him what he thought
of an idea I'd had that if a handler depended on one or more private
subhandlers, it would be tidier to stick these in a script object inside
the main handler. He said he'd had a similar idea, but assumed there'd be
a speed penalty in setting up the script object every time the handler
was called. I did a rough test to try and get an idea of what that
penalty might be. I timed a handler containing just the script object I
was working with at the time - which had two properties and a handler -
against another which just set two variables. I found the timing
differences to be negligible.
My original script object's long been superseded, but if you want to try
the test for yourself, the gist of it is as follows:
on handler1(val1, val2) -- initialise a script object with two
properties
script obj
property prop1 : val1
property prop2 : val2
on privateHandler(val3) -- dummy handler :-)
beep
repeat 99000000 times
set prop2's a to (prop2's a) + prop1 + val3
end repeat
privateHandler(result)
beep
end privateHandler
end script
end handler1
on handler2(val1, val2) -- initialise two variables
set prop1 to val1
set prop2 to val2
end handler2
set t to the ticks
repeat 5000 times
handler1(3, {a:"Hello"})
end repeat
set t1 to (the ticks) - t
set t to the ticks
repeat 5000 times
handler2(3, {a:"Hello"})
end repeat
set t2 to (the ticks) - t
{t1, t2}
--> {16, 15} (on a 400 G3 powerBook)
The original "interior" handler was much longer and the speed difference
was about three ticks.
NG
_______________________________________________
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.