Calculating the execution time for a command
Execution time is the criteria for analyzing an application's efficiency or comparing algorithms.
How to do it...
- The
time
command measures an application's execution time.
Consider the following example:
$ time APPLICATION
The time
command executes APPLICATION
. When APPLICATION
is complete, the time
command reports the real, system, and user time statistics to stderr
and sends the APPLICATION's normal output to stdout
.
$ time ls test.txt next.txt real 0m0.008s user 0m0.001s sys 0m0.003s
Note
An executable binary of the time
command is found in /usr/bin/time
. If you are running bash, you'll get the shell built-in time
by default. The shell built-in time
has limited options. Use an absolute path (/usr/bin/time
) to access the extended functionality.
- The
-o
option will write the time statistics to a file:
$ /usr/bin/time -o output.txt COMMAND
The filename must appear immediately after the -o
flag.
The -a
flag...