Measure script execution time

27

3

In Bash shell, is there a simple way for me to monitor the time taken to run a script and output the time taken?

Jason

Posted 2011-01-04T03:20:05.760

Reputation: 1 619

Answers

36

Yes.

 time script

Where script is the script to monitor the time for.

For instance, time find ~ will output something like this (Depending on the size of your home directory, that is):

real    0m49.139s
user    0m0.663s
sys     0m4.129s

Wuffers

Posted 2011-01-04T03:20:05.760

Reputation: 16 645

@Jason: You're welcome! I'm glad that this helped! – Wuffers – 2011-01-04T13:17:01.050

2

I made a tic/toc timer pair utility called ttic and ttoc. It's available here.

Example use:

$ ttic && sleep 0.4 && ttoc
0.405

To avoid conflicts with an existing tic/toc pairing, an ID can be specified, here foo:

$ ttic foo && sleep 0.5 && ttoc foo

Or assign a random ID, like so:

$ id=$(ttic --unique) && sleep 0.5 && ttoc $id

swalog

Posted 2011-01-04T03:20:05.760

Reputation: 181