I finally figured out why bash has its own “time” the other day. It’s documented, but poorly / subtly:
$ help time
time: time [-p] pipeline
Report time consumed by pipeline's execution.
It’s a parsing issue. The following command times a whole pipeline, which ends up being the length of the longest command, because the command are started in parallel.
$ time sleep 0.1 | sleep 0.2
real 0m0.202s
user 0m0.002s
sys 0m0.001s
This is a pipeline where the first command is /usr/bin/time, so the time is only reporting 0.1 seconds.
$ time {
> sleep .1
> sleep .2
> }
real 0m0.302s
user 0m0.000s
sys 0m0.001s
This won’t work with /usr/bin/time because it will try to run the command {. I probably should copy this into a blog post: http://www.oilshell.org/blog/
I finally figured out why bash has its own “time” the other day. It’s documented, but poorly / subtly:
It’s a parsing issue. The following command times a whole pipeline, which ends up being the length of the longest command, because the command are started in parallel.
This is a pipeline where the first command is /usr/bin/time, so the time is only reporting 0.1 seconds.
Likewise you can do this:
This won’t work with /usr/bin/time because it will try to run the command {. I probably should copy this into a blog post: http://www.oilshell.org/blog/
Perhaps worth mentioning that this article seems to be about the
time(1)from BSD (presumably from opensource.apple.com/source/shell_cmds/shell_cmds-198/time/ specifically) whereas if you’re running Linux you probably havetime(1)from savannah.gnu.org/projects/time. The GNU version uses-vinstead of-l.