LinuxCommandLibrary

times

Report process and child process time

TLDR

Print CPU usage. First line is current shell CPU usage for User and System. Second is all child processes

$ times
copy

SYNOPSIS

times [command]

DESCRIPTION

The times command, often used as a prefix to another command, tracks the time and resources used by both the command itself and any of its child processes. This provides insight into the CPU usage, system time, user time, and wall clock time spent during the execution of a program or script. This information is essential for performance analysis, identifying bottlenecks, and optimizing code for efficiency. times is typically not a standalone command but rather integrated directly into shells like bash.
The output reveals how much processing power your programs or scripts are consuming. By comparing the output before and after modifications to your code, you can determine if your changes have had a positive or negative impact on performance. This information can be crucial when you are trying to optimize your code and reduce resource consumption.

CAVEATS

The times command itself doesn't take any direct command-line arguments; its purpose is to precede other commands to measure their resource usage.
The output format and accuracy of the timings can vary depending on the system and shell being used.
The output can also depend on how your computer is loaded. Be sure to run on an unloaded system to get the most accurate results.

USAGE EXAMPLE

To measure the time it takes to run a command, simply place times before the command.

Example: times sleep 5

This will execute the sleep command and then display the resource usage statistics for that command and any child processes it might have created.

INTERPRETING THE OUTPUT

The times command outputs four values, representing: user CPU time of the shell and its children, system CPU time of the shell and its children, user CPU time of children only, and system CPU time of children only.

The CPU times are measured in clock ticks, which you can convert to seconds by dividing by the number of clock ticks per second. This information is available by running getconf CLK_TCK. User CPU time is the amount of time the CPU spends running code in user mode, while system CPU time is the amount of time the CPU spends running code in kernel mode on behalf of the process. The separate values for children allow to see the resource utilization caused by external processes.

SEE ALSO

time(1), ps(1), top(1), perf(1)

Copied to clipboard