LapTime Reference

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 lap or )).

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]*)

Constructor

start_timer

Make an instance of LapTime

Instance Methods

duration

Return elapsed time form start_timer in msec

lap

Record elapsed time form start_timer in the instance

lap_

Record elapsed time form start_timer given a label in the instance

lap_times

Return time difference in msec between times recorded with lap or lap_

total_times

Return time difference between each lap, lap_ and start_timer in msec

average

Return average of time difference between start_timer and each lap or lap_ in msec