2020-02-26T13:31:52+09:00

LapTime 2.1 : AppleScript の実行時間をミリ秒の精度で測定する AppleScript ライブラリ

LapTime は、AppleScript の実行時間を測定する AppleScript ライブラリです。スクリプトの性能の評価と改善に役立ちます。

AppleScript の実行時間の測定方法として、標準に装備されている curren date が使うことが考えられますが、時間分解能が 1 秒です。精度が悪すぎてスクリプトの性能評価には不向きです。LapTime は Cocoa の NSDate を使うことにより、ミリ秒オーダーの精度で時間を測ります。

機能の変更はささやかですが、内部のコードはガラッと変わっています。AppleScript のオブジェクト指向機能を、我ながら美しく使えたと、悦に入っています。\(^o^)/

変更点:

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