28

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

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Jason
  • 1,869
  • 7
  • 31
  • 40

3 Answers3

37

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
  • 19,020
  • 17
  • 95
  • 126
3

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
  • 191
  • 4
0

If you want to time a chunk of code, you can do:

> time { sleep 3; }

real    0m3.013s
user    0m0.002s
sys     0m0.006s
P i
  • 181
  • 1
  • 2
  • 6