Home > XModules >

Requirements

  • OS X 10.9 or later
    • Developed and tested on macOS 10.14.6.

Download

Version 2.0 -- 2020-02-12

Old Versions

  • macOS 10.13 - Mac OS X 10.4

Dependencies

LapTime

LapTime is an AppleScript library to measure execution time of AppleScript in accurary of a few milliseconds. It is useful to evaluate performance of a script and to tune up the script.

You can measure execution time by using current date command which is AppleScript's built-in command. But time resolution of AppleScript's date class is 1 sec, which is too rough for performance measurements. By using NSDate of Cocoa, the time resolution of LapTime is below a few msec.

The simple usage is using start_timer and duration methods. start_timer generate a new LapTime instance. duration method obtain elapsed time from call of start_timer.

To evaluate required times of parts of your script, use lap and lap_times methods. lap recorods the called time into the LapTime instance generaged by start_timer. lap_times method outputs elapsed times between each lap methods and start_timer.

For precise evaluations of required times of processings in your script, use lap and average. Reapeat execuion of your script many times with repeat statement ,and record each execution time with lap. average calculate an average of time diffrences between each lap and start_timer.

use LapTime : script "LapTime"

(*== Simple Usage ==*)
set tm to LapTime's start_timer()
delay 0.15
tm's duration() -- time from call of start_time
(*151.413917541504 [ms]*)

(*== Measure required times of parts of a script ==*)
set tm to LapTime's start_timer()
tm's lap() -- record the timming
delay 0.1
tm's lap()
delay 0.2
tm's lap()
tm's lap_times() -- pretty print elapsed times between calls of lap()
(*[Lap Times]
0.115990638733 [ms]
100.725054740906 [ms]
201.471924781799 [ms]*)

(*== Take an average of lap times to evaluate precise required time ==*)
set tm to LapTime's start_timer()
repeat 100 times
delay 0.01
tm's lap()
end repeat
tm's average()
(*[Average Time of Laps]
11.234790086746 [ms]*)

History

  • 2.0 -- 2020-02-12
    • First release.
    • Scripting additions don't work on macOS 10.14 or later. This libray is aimed to replace LapTime.oax.