This works:
time ls -l
This does not work
f() { ls -l }
time f
No time output is printed in the second case. Why?
@John1024 gave you the answer for bash
. I try to answer the zsh
tag...
You get the timing statistics, if you spawn a subshell for your function:
% zsh
% f() { sleep 1 }
% time f
% time (f)
( f; ) 0.00s user 0.05s system 4% cpu 1.061 total
% time sleep 1
sleep 1 0.00s user 0.03s system 2% cpu 1.045 total
This adds a little overhead, but as you can see from this (non-faked ;)
) example, it's probably insignificant.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments