Calculating the execution time for a command
While testing an application's efficiency or comparing different algorithms to solve a given problem, the execution time taken is very critical. A good algorithm should execute in a minimum amount of time. Let's see how to calculate the execution time.
How to do it...
To measure the execution time, just prefix
time
to the command you want to run.For example:
$ time COMMAND
The command will execute and its output will be shown. Along with the output, the
time
command appends the time taken instderr
. An example is as follows:$ time ls test.txt next.txt real 0m0.008s user 0m0.001s sys 0m0.003s
It will show real, user, and system times for execution.
Note
An executable binary of the
time
command is available at/usr/bin/time
, as well as a shell built-in namedtime
exists. When we run time, it calls the shell built-in by default. The shell built-intime
has limited options. Hence, we should use an absolute path for the executable (/usr/bin...