I have a bash script file called readspeed
.
I am trying to find how long it takes time to execute a bash script file.
When I run time readspeed
, the following is the output.
$ time readspeed
6
readspeed 174.19s user 286.30s system 99% cpu 7:40.50 total
I'm not sure what user, system, cpu, and total indicated.
What are the differences between user
, system
, and total
?
$ type time
time is a reserved word
$ echo $SHELL
/bin/zsh
Best Answer
The output of
echo $SHELL
shows that you're runningzsh
- notbash
.zsh
is the default shell in recent versions of macOS. Thetime
command is then actually performed by the shell instead of running a seperatetime
program (but it is funnily enough not listed as a shell built-in). The rather terse documentation is available by runningman zshmisc
:The meaning of the TIMEFMT parameter can be found by running
man zshparam
:From this you can learn several things:
The time measurements made by
time
covers both the time used byzsh
itself (for interpreting your shell script) as well the time used by any commands spawned by the shell script to do the actual work.The time measurements are split in a "user" and a "system" part. A program is considered consuming "user" time when it is executing on its own (i.e. doing calculations, moving data around in RAM, etc). It consumes "system" time when it has asked the operating system to do something on its behalf (for example reading data in from a file, sending data on a network, etc).
In addition to the above, you'll see that the last part of the output is the total time. This is understood as being a "wall-clock" time. I.e. the amount of time spent in "user" and "system" mode is determined as the amount of time the program is somehow consuming processor time, whereas the total time is the amount of time passed in the real world - including the time where the program is not actively doing anything and the system is also not doing anything on behalf of the program.
Finally the "99% cpu" part states the ratio between the combined user and system time consumption, and the total wall-clock time spent. For you the "99%" measurement means that your program was in some form actively using the CPU almost all the time. A low number would indicate that the system was busy with other things, and your program had periods of idle time.