Home > XModules >


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


Version 2.1.1 -- 2020-04-15

Old Versions

  • macOS 10.13 - Mac OS X 10.4



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, lap_ and lap_times methods. lap and lap_ recorods the called time into the LapTime instance generaged by start_timer. lap_times method outputs elapsed times between each lap or lap_ methods and start_timer.

lap records only time. lap_ records time with a given label. The label apears in first column of log output of lap_times. The label will help to find the record in the log output.

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 a timming
delay 0.1
tm's lap:"Label 1" -- record a timming with a label
delay 0.2
tm's lap:"Label 2"
tm's lap_times() -- pretty print elapsed times between calls of lap()
(*[Lap Times]
0.099897384644 [ms]
Label 1 101.617097854614 [ms]
Label 2 201.478958129883 [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]*)


  • 2.1.1 -- 2020-04-12
    • Fixed : did not work in OS X 10.9
  • 2.1 -- 2020-02-26
    • Add "lap_" method.
  • 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.