Walker News

How To Measure Time Spent By A Linux Command?

On Linux system using Bash shell, there is a time command that can be used as stopwatch, to measure total time spent and CPU time used by a Linux command.

This time command is actually a built-in command (reserved word) of Bash shell.

By default, the time command displays real time (elapsed time in seconds), user time (number of CPU seconds spent in user mode), and system time (number of CPU seconds spent in system mode):
[walker@localhost] time zip JREx32.zip JREx32.exe
  adding: JREx32.exe (deflated 10%)

real    0m13.628s
user    0m5.570s
sys     0m0.400s

The above example shows how to execute time command to measure total time used by zip program execution.

Note, the default time format returned by the time command can be changed by configuring TIMEFORMAT environment variable, for example:

Where the “%P” tells time command to display CPU percentage, a derived value that calculated from the formula (%U + %S) / %R.

After setting this specific environment variable, the time command will return the defined format as this:
time zip JREx32.zip JREx32.exe
updating: JREx32.exe (deflated 10%)
CPU-USAGE:38.12 REAL:14.31 USER:5.06 SYSTEM:0.39

For more information on how to configure the environment variable, type man bash and locate the keyword TIMEFORMAT.

Custom Search

2017  •  Privacy Policy