指定の開始時刻から終了時刻まで、hh:mm形式の文字列を15分間隔でリスト出力するAppleScriptです。
ありもののサブルーチンを組み合わせて即席で作ったCocoa版のルーチンと、ChatGPT(GPT-5)に書かせた非Cocoa版のルーチンの2つがあり(ChatGPTにCocoa使用を指定せず)、速度を比較してみたら……
非Cocoa版のルーチンのほうが6倍ぐらい高速でした。データが小さすぎるとか、処理内容が小さすぎる場合にはCocoaの機能を利用しないほうが高速に処理できる場合があります。
Shane Stanleyの処理時間計測アプリ「ScriptGeek」が、かなりCocoa Scriptingの登場初期から存在しており、不思議に思ってきたものですが……処理内容の規模によってはCocoa Scriptingのほうが遅くなるケースがあるため、実際に書いて動かして計測してみないと、Cocoa Scriptingで高速化が達成できるかわからないところです。
このほか、AppleScriptのランタイム環境が何になるかによって実行速度は変わってきます。Xcode上で開発するCocoa Applicationなども実行特性が違うため、やはり動かして計測してみないと何がベストなのかはわかりません。
ただ、この程度の処理であれば、0.0028秒が0.4秒になったところで、何か実用上の差異が発生するわけでもありません。
AppleScript名:15分メッシュの時間文字列を生成.scptd |
— – Created by: Takaaki Naganoya – Created on: 2025/08/13 — – Copyright © 2025 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set aRes to generateWorkUnitList() of me –> {"5:15", "5:30", "5:45", "6:00", "6:15", "6:30", "6:45", "7:00", "7:15", "7:30", "7:45", "8:00", "8:15", "8:30", "8:45", "9:00", "9:15", "9:30", "9:45", "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00", "19:15", "19:30", "19:45", "20:00", "20:15", "20:30", "20:45"} on generateWorkUnitList() set hList to {} repeat with h from 5 to 20 by 1 repeat with m from 0 to 59 by 15 if {h, m} is not equal to {5, 0} then set mStr to numToZeroPaddingStr(m, 2, "0") set the end of hList to (h as string) & ":" & mStr end if end repeat end repeat return hList end generateWorkUnitList –整数の値に指定桁数ゼロパディングして文字列で返す on numToZeroPaddingStr(aNum as integer, aDigit as integer, paddingChar as text) set aNumForm to current application’s NSNumberFormatter’s alloc()’s init() aNumForm’s setPaddingPosition:(current application’s NSNumberFormatterPadBeforePrefix) aNumForm’s setPaddingCharacter:paddingChar aNumForm’s setMinimumIntegerDigits:aDigit set bNum to current application’s NSNumber’s numberWithInt:aNum set aStr to aNumForm’s stringFromNumber:bNum return aStr as text end numToZeroPaddingStr |
AppleScript名:15分メッシュの時間文字列を生成(高速).scpt |
— – Created by: Takaaki Naganoya – Created on: 2025/08/13 — – Copyright © 2025 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set mList to retWorkingMeshStrList() of me –> {"5:15", "5:30", "5:45", "6:00", "6:15", "6:30", "6:45", "7:00", "7:15", "7:30", "7:45", "8:00", "8:15", "8:30", "8:45", "9:00", "9:15", "9:30", "9:45", "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00", "19:15", "19:30", "19:45", "20:00"} on retWorkingMeshStrList() set startSeconds to (5 * 3600) + (15 * 60) — 5:15 の相対秒 set endSeconds to (20 * 3600) — 20:00 の相対秒 set intervalSeconds to 15 * 60 — 15分間隔 set timeList to {} repeat with t from startSeconds to endSeconds by intervalSeconds set h to t div 3600 set m to (t mod 3600) div 60 — 2桁表示に整形 –set hStr to text -2 thru -1 of ("0" & h) set hStr to h as string set mStr to text -2 thru -1 of ("0" & m) set end of timeList to (hStr & ":" & mStr) end repeat return timeList end retWorkingMeshStrList |