Benches macOS

15

Why do Applescript applications run 60% s…

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have a bench mark script that I have used on the past several generations of iMac hardware and systems to test speed. With Leopard, I have noticed that when I adjust the script to show 100% on the compiled application, the source script run through script editor runs faster, producing a result of 240%. I always thought that complied script should run faster. Why is this happening?

15 replies

Sign in or join Beachball Help to reply.

  1. 0

    Hiroto

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello Al Gunther,

    It is a known issue.

    I'm not sure why it's slower in applet, but I know a method to improve its performance.

    Please see this archived thread:

    http://discussions.apple.com/thread.jspa?messageID=5223875#5223875

    Cheers,

    H

  2. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hiroto,

    Thanks for the archived thread. That method did improve my application performance but it stil runs 50% slower than through the editor. It would be interesting to know why it's still that slow. I am assuming that if I were to incorporate it into a cocoa application, it would run faster than through the script editor.

    Al

  3. 0

    osimp

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I posted the script in the thread Hiroto referenced. Because of your response, I went back and had another look at Hiroto's "fix," with these results:

    Without Hiroto's "fix" the script editor version of the repeat sequence runs in ~ 164 ticks, whereas the applet version takes ~544 ticks.

    With Hiroto's "fix" the corresponding numbers are ~165 and ~165 ticks (the fix obviously is 100% in this case).

    The "fix" I applied was exactly this:

    *Added at beginning of script:*

    script TestRunTime

    *Added at end of script:*

    return me

    end script

    set TestRunTime to run script TestRunTime

    There appear to be two differences in your case:

    1) Your script

    2) Your OS

    neither of which I have -- so I can't play with those.

    However,
    you could try my script, with and without the "fix," and see how it fares with Leopard.

    For clarity, I've posted the script here. However, note these things:

    1) I've removed my timing mechanism, which was based on the scripting addition "the ticks" from Jon's Commands (this won't work on an Intel MAC). But, at its fastest, the script takes about 3 seconds to run, and, at its slowest about 9 seconds -- so you should be able to gauge these differences with a watch or the system clock.

    2) The script needs a picture file. I've deleted the one I used. You need to insert the path to a .jpg file (for example) that's on your computer. The place you need to do this is clearly indicated in the script I've posted.

    --BEGIN SCRIPT

    --(uncomment the following line, and 3 lines at the end of the script, to implement Hiroto's "fix")

    --script TestRunTime

    tell application "Finder" to set PictPath to "*INSERT PATH TO YOUR .jpg FILE HERE*"

    tell application "Preview"

    activate

    open PictPath

    tell application "System Events"

    repeat 20 times

    tell process "Preview"

    tell menu bar 1

    tell menu bar item "Tools"

    tell menu "Tools"

    click menu item "Flip Horizontal"

    end tell

    end tell

    end tell

    end tell

    delay 0.1

    end repeat

    end tell

    close window 1 saving no

    end tell

    --(uncomment the next 3 lines, and 1 line at the beginning of the script, to implement the fix)

    --return me

    --end script

    --set TestRunTime to run script TestRunTime

    --END SCRIPT

    If you don't see a roughly 3x speed improvement in the applet with the "fix," that would suggest that Leopard and Tiger respond to the fix differently.

    If you do see a roughly 3x improvement with the above script, that would suggest that your benchmark script doesn't respond to the fix similarly. Would it be possible to post that script?

    (Of course, I'm assuming that the above script will basically run on your setup.)

    I'm really interested in your results.

  4. 0

    osimp

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Oh yes. One other difference is that you're using an Intel and I'm using a PPC. Conceivably, that could be important.

  5. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Your script hangs up after the first rotation in Preview on my system. I have version 4.1 of Preview with Leopard and Intel which is not apparently scriptable. I tried to convert the script to run on GraphicConverter but could not get the GUI to work at all. But GC is very scriptable so I modified the script accordingly.

    Runtime is 0.773 seconds normal, 0.682 seconds in 'run script' osax. This seems comparable to the improvement that I had in my own script.

    The following is my version of your routine. (I ran it with a delay inserted and it does flip the photo 20 times.)

    script o

    set secs to getSec()

    doRoutine()

    set secs to getSec() - secs - 0.013 --editor

    --set secs to getSec() - secs - 0.021 --application

    if secs < 0 then set secs to secs + 60

    tell application "TextEdit"

    set dat to text of document 1

    set text of document 1 to dat & "Seconds= " & secs & return

    end tell

    on doRoutine()

    set PictPath to "Macintosh HD:Users:agunther:Desktop:Picture 3.jpg" as alias

    tell application "GraphicConverter"

    activate

    open PictPath

    repeat 20 times

    mirror window 1 in horizontal

    end repeat

    close window 1 saving no

    end tell

    end doRoutine

    on getSec()

    try

    do shell script "defaults read b"

    on error errorText

    -- errorText is current date log

    text 18 thru 23 of errorText

    -- extracts seconds portion in ##.###

    end try

    end getSec

    end script

    run script o -- use 'run script' osax to run your main code

  6. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I forgot. The with and without run times for the above script run as an applet were 0.852 and 1.662 seconds respectedly. So the degree of improvement is considerably more as an applet.

  7. 0

    osimp

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    It's true that Preview is not normally scriptable beyond basic commands. But System Events is, and that's what implements the GUI.

    In my script, the delay (line 17) is essential; without it, the "Apple" menu inexplicably opens at some point into the script.

    I found that a minimum 0.1 second delay would prevent that. It would be interesting to see if increasing the delay would prevent the hang on your machine. A small increase might do it, but I'd start with 2 or 3 seconds and and work my way down toward the 0.1 value.

    If you can make it work with a very small delay, then we'd be comparing apples with apples. Remember to compare applet versions of the script with and without the fix. The script version doesn't seem to be affected by the fix.

  8. 0

    Hiroto

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello Al Gunther,

    I've forgotten to mention this important factor.

    If you have saved your applet as normal application (not application bundle), it should be run via 'Rosetta' under x86 Mac and be slower than necessary. Saving it as application bundle will make it 'Universal Binary'.

    Just in case,

    H

  9. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    osimp,

    I found that your script on my machine would run consistently with a 0.4 delay, but not with a 0.3 delay. "Close window saving no" would require GUI scripting on my system so I just disabled it. Here are my results:

    Seconds= 8.586 in editor using 'run script' osax

    Seconds= 8.48 above repeated

    Seconds= 8.77 in editor NOT using 'run script' osax

    Seconds= 8.755 above repeated

    Seconds= 8.729 as Applet using 'run script' osax

    Seconds= 8.73 above repeated

    Seconds= 16.027 as Applet NOT using 'run script' osax

    Seconds= 16.493 above repeated

    The difference in Applet times was a huge surprise to me since 20 x 0.4 = 8 seconds of the time is used for delays in either case. Subtracting that out would make the difference much greater.

  10. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hiroto,

    It's amazing to me that your predictions are quite true. (I'm not amazed at your ability to predict, only that it actually happens.)

    I ran a test using my Graphics Converter routine since it contains no delays, with the following results:

    Seconds= 1.337 Applet not bundled

    Seconds= 1.671 (repeated)

    Seconds= 0.875 Applet using 'run script' osax not bundled

    Seconds= 0.856

    Seconds= 1.792 Applet bundled

    Seconds= 1.46

    Seconds= 0.681 Applet bundled using 'run script' osax

    Seconds= 0.698

  11. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hiroto,

    In looking back at my results testing, I see now that if I include the 'run script' osax and the bundle application option, the script run times are the same as with the script editor. So, the answer to my question is that I have not been doing it to best advantage. I can accept that, so I am marking this question solved.

    Thanks to both you and osimp

  12. 0

    Hiroto

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello Al Gunther,

    My pleasure. Glad to know it helped.

    Hiroto

  13. 0

    osimp

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Since you consider the matter solved,
    ALL the credit for that goes to Hiroto.

    I continue to be amazed at Hiroto's success in solving "OS X problems" while using 9.1; I've learned not to ignore his suggestions, even if they completely baffle me.

    On another subject: I had not previously seen (or thought of) your approach to script timing, but I think it will be useful if I get involved with Intel machines. "The ticks" scripting addition probably yields somewhat more accurate* results but it won't work with Intel.

    * I ran a couple comparison tests, using a delay of 1 second or 10 seconds as the entire code, repeating 10 to 100 times. With the ticks, there occurred only one value of deviation, 16 msec, and that occurred infrequently. With the defaults approach, there were numerous deviations, typically 15 to 45 msec. There's certainly more to judging accuracy that these numbers, but both seem to be trustworthy solutions.

  14. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    osimp,

    I'm not sure why ticks would be more accurate than the milliseconds from "the default" method

    the script:

    ---------------

    try

    do shell script "defaults read b"

    on error e

    return e

    end try

    --------------

    returns: "2008-04-01 18:26:19.729 defaults[20413:613]

    Domain b does not exist"

    --------------

    The first part of this comes from the system clock and my routine only pickes up the millisecond portion of the time. The inaccuracy is the fact that the routine takes 120+ milliseconds for one call, depending on how it's run. I ran a loop of 1000 calls and came up with 12 seconds for bundled app and slightly more for running scrip through the script editor. So, that's where the .012 comes from that I subtract off the routine's time. (includes half the start call time and half the finish call time)

    Do you account for the time it takes to read the number of ticks?

    As to credit for answering the question, I didn't know how to give partial credit. You did contribute also. Thanks!

    Al

  15. 0

    Al Gunther

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    While the problem I was having arose from my compling for PPC instead of Intel, the over looked issue was that I had no real need to compile either way. I just discovered that there is no need to save my scrips bundled as applications or otherwise just to be able to run them from the menu bar. The scripts run as scripts without aid of the script editor when placed in the user library script folder. Perhaps everyone but me knew that, but I mention it here in case others like me have not discovered this.

    Thanks again.