I imagine time A | B would only measure the time taken to run A (since the argument to time is A). What's the solution ?
Asked
Active
Viewed 52 times
2 Answers
1
Depends on the shell. e.g. Bash has a keyword time
that times the whole pipeline. An external implementation of time
would only time A
in your example. A workaround might be to explicitly run an extra shell:
time sh -c "A | B"

Gilles 'SO- stop being evil'
- 829,060

ilkkachu
- 138,973
0
You could also use a subshell, e.g.
time ( A | B )
at least when time
is the bash builtin (but then a subshell is useless). If you want to use the time(1) command (see this) you'll better explicitly run some sh -c
like answered by iikkachu

Basile Starynkevitch
- 10,561
time
is not a builtin, but a keyword (in bash, and in ksh and zsh which have the same feature). It has to be so thattime
applies to the following compound command and not just to a simple command. – Gilles 'SO- stop being evil' Jul 11 '17 at 23:42