• 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: Script Speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Speed


  • Subject: Re: Script Speed
  • From: Alex Zavatone <email@hidden>
  • Date: Fri, 09 Nov 2012 15:45:12 -0500

If you're running it through SD, have you turned debugging off?

Are you running it as a compiled app?

If so, are you using the delay command at all?

Whenever this happens, the first thing I do is turn a timer property on and then whenever an operation is complete, I issue a logOperation like so:

on logOperation(operationName)
set elapsedTime to (the (time of the (current date)) - pStartTime) as string
log operationName & " - " & elapsedTime
end

This requires that you declare a property called pStartTime at the start of your script like so:

property pStartTime : the time of the (current date)

BUT, that doesn't give you millisecond granularity.  Thankfully, someone already solved this but he (me) forgot all about it until trying to give you an answer.

Thanks to MacGrunt.com where my previous solution that I completely forgot about was saved for posterity.

http://macgrunt.com/2011/10/13/timing-applescripts/#comment-821

In any case, here's an elapsed time script that is accurate down to the millisecond that I just made for you.

Just call InitTimer() and then whenever you issue a command and want to see how long it took from the start, call logOperation("the thing that I did") as shown in the run handler.
If you want to track the time it takes between operations, just call initTimer() again right after you call logOperation.

Cheers.

-- 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.
-- http://macgrunt.com/2011/10/13/timing-applescripts/#comment-821
-- 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 1 -- horrible command.  Use the shell sleep command instead.
logOperation("Delay 1")


do shell script "sleep 1"
logOperation("shell sleep 1")
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


 _______________________________________________
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

  • Follow-Ups:
    • Re: Script Speed
      • From: Thomas Fischer <email@hidden>
References: 
 >Script Speed (From: Paul Abney <email@hidden>)

  • Prev by Date: Re: Script Speed
  • Next by Date: Re: Script Speed
  • Previous by thread: Re: Script Speed
  • Next by thread: Re: Script Speed
  • Index(es):
    • Date
    • Thread