LoginSignup
0
0

AppleScript で 0.1 秒単位の処理時間を計測する

Last updated at Posted at 2023-12-01

current date では秒単位でしか計測できない。

do shell scriptdate +%N しようとしたが、macOS の date コマンドは BSD date のため +%N オプションが利用できない。

Objective-C を利用する。

use AppleScript version "2.4"
use framework "Quartz"
use scripting additions

set startTime to current application's NSDate's timeIntervalSinceReferenceDate()
-- 計測したい処理
set endTime to current application's NSDate's timeIntervalSinceReferenceDate()
set elapsedTime to (round (endTime - startTime) * 10) / 10
set elapsedTime to ((round (elapsedTime / 60) rounding down) & "m" & elapsedTime mod 60 & "s") as string
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0