Le 23 sept. 2006 à 15:36, Leif Öquist a écrit : On Sep 22, 2006, at 9:10 AM, Leif Öquist wrote:
"From what I saw of your earlier shown test code, you need to add "activate" after "tell app "Finder"". That does all the difference."
On Sep 23, 2006, at 05:35 AM, Michelle Steiner wrote:
"That didn't help."
Now I'm surprised.
When I runned your test code on my home machine, an old G4 350 MHz 192 Mb RAM, the script executed in approximately 26 seconds. When I added the 'activate' command to the tell block, the runtime was reduced to approximately 4 seconds.
I did the same thing with my own test code (once) during my test sessions with the Intel Mac's - with and without the 'activate' command included in the tell blocks. Without having literally clocked it, the difference in execution time was large and obvious.
A guy on my local Mac forum, by the way, runned my posted test code on an Intel Machine saved as an application bundle, and got the same approximate runtime of 1 second. So for the moment I'm convinced that the original problem is solved.
Hello
It seems that you forgot to read Christopher Nebel's explanations.
Just to refresh memories: Objet : Rép : AppleScript runs slow on Intel Macs Date : 22 septembre 2006 03:03:21 HAEC
But why does this script take anywhere from 18 to 25 seconds on a 1.83 GHz Intel iMac?
tell application "Finder" repeat 1500 times get current date end repeat beep end tell
Yet this one is almost instantaneous set x to 0 tell application "Finder" repeat 1500 times set x to x + 1 end repeat beep end tell
Because the first one sends 1500 events to the Finder (which may be busy doing other things, hence the variance), and the second one doesn't. Math operators are executed entirely in-process, regardless of any "tell" block. Try watching the event log.
I read C. Nebel's explanations and gathered your samples. I ran the synthetic script:
set avant1 to current date tell application "Finder" repeat 5000 times get current date end repeat beep end tell set avant2 to current date tell application "Finder" activate repeat 5000 times get current date end repeat beep end tell set avant3 to current date
activate repeat 5000 times get current date end repeat beep
set avant4 to current date set x to 0 tell application "Finder" repeat 5000 times set x to x + 1 end repeat beep end tell set avant5 to current date set x to 0
repeat 5000 times set x to x + 1 end repeat beep set apres to current date set durees to "" & (avant2 - avant1) & return & (avant3 - avant2) & return & (avant4 - avant3) & return & (avant5 - avant4) & return & (apres - avant5)
The result is: 84 61 1 0 0
What does this means?
First, from my point of view, the 1.38 ratio between the two first value is not really important but the three last are.
They show that your tests are not measuring the speed of AppleScript but the time you wasted when encapsulating instructions having nothing to do with the Finder in a tell Finder block.
Doing that, you ask AppleScript to search in the Finder dictionnary for commands which are not Finder's ones so after wasting time, it search in Standard Additions dico.
All the job done in the tell Finder block is wasted time and may take more or less time taking in account what the Finder is already busy with.
To be short you where not mesuring how quick or fast is Applescript but how poor are the tested codes. |