by jimrandomh · 9y ago · 0 comments
time foo |bar
Then the result is the total time taken by foo and bar together. This requires it to have special-case syntax. Whereas /usr/bin/time foo |bar
Would run foo and give its time statistics as input to bar. time echo | sleep 1
vs. /usr/bin/time echo | sleep 1
The former times the entire pipeline whereas the later only times the first command in the pipe.echo | /usr/bin/time sleep 1
As an example :
sleep 2 | /usr/bin/time sleep 1
This gives an output of "1 second" even though the entire pipeline took 2 seconds.
/usr/bin/time foo |bar
would actually give the output of foo as input to bar, since the time statistics go to stderr.http://unix.stackexchange.com/questions/197809/propose-addit...
Furthermore, each stream should be possible to pipe to a different process if you wish independently of the other streams.
To a small degree this might be possible already with named pipes.
I still don't use it enough, but when it comes to scripting PS's objects beat the hell out of these
I think socket pairs would be great for it.
Nothing implemented yet!
time foo=bar
echo $foo
and it will correctly print out "bar". It can't do this if it executes the command in a subshell. Or similarly you can say `time cd /foo` and it will actually change the current working directory. time {
sleep 0.1
sleep 0.2
}
# result is 0.3 seconds
which you obviously can't do with an external command. I wrote about that here:https://lobste.rs/s/hwgt2h/usr_bin_time_not_command_you_thin...
time sh -c 'foo | bar' pi@pi:~ $ time (for x in {1..1000}; do time echo | sleep 0.01; done 2>/dev/null)
real 0m24.173s
pi@pi:~ $ time (for x in {1..1000}; do time sh -c 'echo | sleep 0.01'; done 2>/dev/null)
real 0m25.170s
pi@pi:~ $ time (for x in {1..1000}; do time bash -c 'echo | sleep 0.01'; done 2>/dev/null)
real 0m33.643sIt's really not more than that: an optimization.