Thank you Thomas. Glad to know this exists. Even though you are 100% correct, if you run my script using delay and sleep times of 0, the whole script executes in less than one millisecond, so the overhead might not be as bad as expected.
FYI, the test system is a 10.6.8, 17" 2.3 GMz i7 MBP with 16 GB of RAM.
-- script elapsedTime
-- Alex Zavatone 11092012
-- thanks to
macgrunt.com who actually remembered that I solved this once before and put up a web page about it since I
-- forgot all about it.
-- This is what happens when your mother has a habit of dropping you on your head on a regular basis.
property pStartTime : 0
on run
initTimer()
delay 0 -- horrible command. Use the shell sleep command instead.
logOperation("Delay 0")
do shell script "sleep 0"
logOperation("Shell sleep 0")
end run
on initTimer()
set pStartTime to getMS()
end initTimer
on logOperation(operationName)
set elapsedTime to getMS() - pStartTime
log (operationName & " - " & elapsedTime)
end logOperation
on getMS()
set msRightNowScript to "perl -e 'use Time::HiRes qw(time); print time'"
set msTime to ((do shell script msRightNowScript) as integer) * 1000
return msTime
end getMS
-- end script