Here's a script written by others, most notably Shane Stanley.
I think it should provide what you asked for.
use
AppleScript
version
"2.4"
use
scripting additions
use
framework
"Foundation"
timer("Start")
# YOUR CODE
repeat with i from 1 to 10
delay 0.123
end repeat
timer("STOP")
###——————————————————————————————————————————————
# timer(pAction) Calculate and Log Execution Time
#
# Ver 1.1 2016-02-21
#
# REF: The base ASObjC code was provided by Shane Stanley
#
# HOW TO USE:
# • You may want to run the script at least 3 times
# • The first run may be high
# * For more extensive/exhaustive testing, see:
# Script Geek app by Shane Stanley
# http://www.macosxautomation.com/applescript/apps/Script_Geek.html
#
# REQUIRES:
# • These two statements at top of main script:
# use scripting additions
# use framework "Foundation"
# • Yosemite+
# • function formatSeconds(totalSeconds)
# (provided below)
###——————————————————————————————————————————————
on
timer(pAction)
global
gTimerStartDate
if (pAction =
"start") then
-- START CASE
set
gTimerStartDate to
current application's
NSDate's
|date|()
log
"START: " & ((current date)
as text)
else
-- HANDLE CASES OTHER THAN START
set
durationNum to -(gTimerStartDate's
timeIntervalSinceNow())
--- IF ≥ 60 SEC, FORMAT AS HR MIN SEC ---
if durationNum ≥ 60 then
set
durationStr to
formatSeconds(durationNum)
else
set durationStr to (round
(durationNum) * 1000) / 1000.0 &
" sec"
end if
-- durationNum ≥ 60
log
pAction &
": \n • " & ((current date)
as text) &
"\r • EXECUTION TIME: " &
durationStr
end if
-- (pAction = "start")
end
timer
###——————————————————————————————————————————————
###——————————————————————————————————————————————
# formatSeconds(totalSeconds) Convert Seconds to HR MIN SEC format
#
# Ver 1.1 2016-02-21
#
# REF: http://www.jesseweb.com/coding/applescript/format-seconds-hhmmss/
###——————————————————————————————————————————————
on
formatSeconds(totalSeconds)
set
theHours to (totalSeconds
div hours)
set
theRemainderSeconds to (totalSeconds
mod hours)
set
theMinutes to (theRemainderSeconds
div minutes)
set
theRemainderSeconds to (theRemainderSeconds
mod minutes)
set
theRemainderSeconds to (round
(theRemainderSeconds * 100)) / 100.0
# set theTimeString to theHours & ":" & theMinutes & ":" & theRemainderSeconds as text
set
theTimeString to
theHours &
" hr " &
theMinutes &
" min " &
theRemainderSeconds &
" sec" as
text
return
theTimeString
end
formatSeconds
###——————————————————————————————————————————————