AppleScript Timing Tests

I used to use Jon’s Commands to get ‘the ticks’ to do precise timing of routines. Now in the 64 bit world, I needed a replacement. Here it is, complete with my routine performance comparison test code.

property kPreciseTime : "perl -e 'use Time::HiRes qw(time); print time'"
on run
        set iterate to 1000
        set t1 to do shell script (kPreciseTime)
        repeat iterate times
            -- block comment
        end repeat
        set t2 to do shell script (kPreciseTime)
        repeat iterate times
            -- insert test two here
        end repeat
        set t3 to do shell script (kPreciseTime)

        set ta1 to (t2 - t1)
        set ta2 to (t3 - t2)

    on error errMsg number errNum
        return errNum
    end try
    return 0
end run

From this I learned (most recently) that when writing to a file, it is better to concatenate text into a larger chunk and do fewer writes.

google_pluslinkedingoogle_pluslinkedinby feather