time is a useful utility for measuring the time elapsed (in seconds) after a command is run.
time (sleep 1) ( sleep 1; ) 0.00s user 0.00s system 0% cpu 1.005 total
The output stats are as follows:
- the total time elapsed by the command,
- the time consumed by system overhead,
- the time until the utility is executed to stderr (standard error stream).
If there’s a lot of text in the stdout (standard output) due to the script or command, you can hide it like so:
time (yes hi | head -n 10) 2>&1 1>/dev/null ( yes hi | head -n 10; ) 2>&1 > /dev/null 0.00s user 0.00s system 130% cpu 0.005 total