18 December 2021
When I need to know execution and system execution time elapsed for a script there is a command that I use time
Note: all example below could be execute in a container:
docker run -it ubuntu /bin/bash
Example:
time sleep 2
The output is:
real 0m2.002s
user 0m0.000s
sys 0m0.002s
Where:
- real is the elapsed time, including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete);
- user is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure;
- sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CPU time used by the process. See below for a brief description of kernel mode (also known as 'supervisor' mode) and the system call mechanism.
User+Sys will tell you how much actual CPU time your process used. Note that this is across all CPUs, so if the process has multiple threads, it could potentially exceed the wall clock time reported by Real.
References