≡ Menu

How to measure program execution time in Linux?

Question – I need to measure the execution time that my program takes to execute on the shell command line in Linux. Is there a Linux command or directive that can do this?

The time command can be used to do this on a Bash shell (or any other shell). The time command takes as a argument the program that should be run and any arguments to it. In this article, I will make you understand the output of the time command and explain what the output means.

The syntax to use the time command is the following:

time ProgramName [arguments]

For example, I want to measure the time it takes to get the DNS records of my domain name:

time host ewhathow.com

This outputs somthing like the following:

ewhathow@ewhathow.com [~]# time host ewhathow.com
ewhathow.com has address
ewhathow.com mail is handled by 0 ewhathow.com.

real    0m0.333s
user    0m0.003s
sys     0m0.001s
ewhathow@ewhathow.com [~]#

The bottom bolded text is the output of the time command. The time command will run any program and arguments passed to it and measure the execution time of that program or application.

As you can see, there are three durations that time outputs:

real: The total elapsed time between start and end of the program.
user: The user CPU time that the program used. This includes all user mode library calls that the program made.
sys: The system CPU time that the program used. This includes only the kernel system calls and not any user library calls.

So in the above output, the real time is 333 milliseconds, the user time is 3 milliseconds and the system time is 1 milliseconds. In most cases, what you are looking for is the real time, which is the total execution time in seconds for the application to run.

Incoming search terms:

  • command for execution time in centos (1)
  • how to check time execution in debian (1)
  • linux execution time shell (1)
  • linux time measurement of command execution (1)

{ 0 comments… add one }

Leave a Comment