timing scripts [Re: Timers in AppleScript?]
timing scripts [Re: Timers in AppleScript?]
- Subject: timing scripts [Re: Timers in AppleScript?]
- From: has <email@hidden>
- Date: Mon, 15 Jul 2002 20:12:28 +0100
Paul Skinner wrote:
>
I use this script object.
Hey there Paul, have you considered getting down-n-dirty with some basic
OOP these days? I think you'd like it. For example, instead of having one
big complex module tracking 32 times (with whatever limitations and
overheads that involves), you could create any number of small, simple
objects, each responsible for a single time:
======================================================================
script secondsTimer
on newTimer()
script
property _startTime : current date
--
on elapsedTime()
(current date) - _startTime
end elapsedTime
end script
end newTimer
end script
set timer1 to secondsTimer's newTimer()
delay 2
timer1's elapsedTime()
--> 2
======================================================================
Providing variations on this theme that use other osax (Jon's, Precision
Timer, etc.) is then a simple matter of designing additional objects that
provide the same interface [i.e. support the same newTimer(), elapsedTime()
calls] but internally using those other osaxen instead. You could then
bundle the whole lot as "timerLib" or something, then have the user load
the library via:
set timerLib to init() of (load script pathToTimerLib)
and put all your automated osax checks into the init() method as they only
need to be run once, rather than having them occur every time a timer is
started or stopped (i.e. the simpler the timer's own code is, the better).
--
Incidentally, any propeller heads out there know how much, if any, effect
other processes on the machine will have on timing accuracy? (I'm assuming
that there will always be some variation in timings anyway, due to garbage
collection and other unpredictable events occurring within AS itself, but
what about everything outside AS?) And if other processes can have an
impact, what might be done to lessen that?
--
>
--Attempts to use the GetMiliSec OSAX if it is installed.
A new timing osax? For X? Cool. (BTW, I think Standard Additions is waaaay
overdue for having something like this. Can't stress how valuable it is for
profiling & optimisation.)
>
set currentTime to GetMilliSec
Hrmm... is this naming style becoming habit amongst osax authors? I really
hope not: using compound names like these for osax [or application] calls
is likely to increase the number of keyword-variable name collisions in
user's scripts. As if AppleScript's ghastly keyword swamp isn't treacherous
enough already. >:(
has
--(AS Geek joke)
on current date
continue current date
return result - (1 * days)
end current date
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.