• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Milliseconds elapsed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Milliseconds elapsed?


  • Subject: Re: Milliseconds elapsed?
  • From: Jim Underwood <email@hidden>
  • Date: Tue, 06 Sep 2016 00:21:59 +0000
  • Thread-topic: Milliseconds elapsed?

Brian,

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

###——————————————————————————————————————————————





Best Regards,

Jim Underwood
aka JMichaelTX


From: <applescript-users-bounces+jmichael=email@hidden> on behalf of Brian Christmas <email@hidden>
Date: Mon, Sep 5, 2016 at 7:13 PM
To: "ASUL (AppleScript)" <email@hidden>
Subject: Fwd: Milliseconds elapsed?


Sorry, did not copy all of the script, and did not proof read the send. I’m slack.

setato my milleDT()
delay 1.5
setbto my milleDT()

try
setato aas date
onerror errmsg
tellapplication "System Events"
activate
display dialogerrmsggiving up after 10
endtell
endtry

try
setcto b - a
onerror errmsg
tellapplication "System Events"
activate
display dialogerrmsggiving up after 10
endtell
endtry

onmilleDT()
try
do shell script "defaults read b"
onerror errorText
text 1 thru 23 of errorText
endtry
endmilleDT

Regards

Santa

And what, you ask, was the beginning of it all?
And it is this......
Existence that multiplied itself
For sheer delight of being
And plunged with numberless trillions of forms
So that it might
find
itself
innumerably

Sri Aurobindo




And what, you ask, was the beginning of it all?
And it is this......
Existence that multiplied itself
For sheer delight of being
And plunged with numberless trillions of forms
So that it might
find
itself
innumerably

Sri Aurobindo



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Milliseconds elapsed? (From: Brian Christmas <email@hidden>)
 >Fwd: Milliseconds elapsed? (From: Brian Christmas <email@hidden>)

  • Prev by Date: Fwd: Milliseconds elapsed?
  • Next by Date: Re: Milliseconds elapsed?
  • Previous by thread: Fwd: Milliseconds elapsed?
  • Next by thread: Re: Milliseconds elapsed?
  • Index(es):
    • Date
    • Thread