Measure the execution time of a program in Linux

By using the time command, you can measure how long a program takes to execute.


Sometimes, when you run larger batch jobs, you need to know how long they take to complete. This is exactly what the time command is used for.

For example, to measure the execution time of the fictional script run_my_batch_job.sh:

Command
time run_my_batch_job.sh

This will output something similar to this:

Output
real    9m38.935s
user    3m14.820s
sys     6m3.263s

From the output above, you can see that the batch job took 9 minutes and 38 seconds to run. You can also see that 3 minutes were spent in user mode and 6 minutes in system mode.

Now you know how long the job took to execute. If you run the same job again, you’ll know how much time you have left for other tasks.

Last updated

Was this helpful?