How would you calculate the time it took to run a command? Specifically, I want to know the time it takes to return a value in a Shell command. I wrote this up, would it work? (Psuedocode)

print b-a

If translated into Applescript would this work? Is there a better way to do this when calculating the runtime of a shell command (the command is run via do shell command)?

  • Is executing the shell command via AppleScript a hard requirement (and if yes, why) or would you also be fine with having a way to measure execution time directly in the shell? – nohillside Jul 22 '15 at 15:30
  • @patrix It would be fine to measure execution time directly in the shell. – APCoding Jul 22 '15 at 15:34

It’s not AppleScript, but is there a reason why the time command isn't applicable? It’s used like this:

time <command>
time find /opt
time tar xf bigFile.tar.bz2

It gives output like this:

real    0m0.044s
user    0m0.000s
sys     0m0.008s
  • Is there a way to have the output in nanoseconds? – APCoding Jul 22 '15 at 15:34
  • Hmmm, I’ve done a bit of reading and it appears not :( Though I wonder if time smaller than milliseconds would be represented accurately using standard hardware—no idea, just thinking aloud. – forquare Jul 22 '15 at 15:48
  • Just an FYI... From the BUGS section of time(1) man page, "The granularity of seconds on microprocessors is crude and can result in times being reported for CPU usage which are too large by a second." – user3439894 Jul 22 '15 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .