Search code examples
performancezshtiming

Does ZSH's time command take any arguments like -p?


I recently installed the developer beta of macOS 10.15 Catalina, which defaults to ZSH instead of BASH.

I have time installed as a binary in /usr/bin/time, and use that to time some of my scripts. ZSH, however, has this as a built-in command. My problem is that I usually use time -p to format its output in a way I prefer, but that doesn't seem to be possible on ZSH.

According to man time:

     -p      The output is formatted as specified by IEEE Std 1003.2-1992 (``POSIX.2'').

This doesn't seem to apply to ZSH's built-in, and ZSH doesn't seem to be using my installed time binary:

BASH

bash-5.0$ which time
/usr/bin/time
bash-5.0$ time echo hello; echo $?
hello

real    0m0.000s
user    0m0.000s
sys 0m0.000s
0
bash-5.0$ time -p echo hello; echo $?
hello
real 0.00
user 0.00
sys 0.00
0

ZSH

is-mbp-bleggiero% which time
time: shell reserved word
is-mbp-bleggiero% time echo hello; echo $?
hello
0
is-mbp-bleggiero% time -p echo hello; echo $?
zsh: command not found: -p
-p echo hello  0.00s user 0.00s system 74% cpu 0.001 total
127

And that looks odd to me; it seems to be including the info I want (user vs system & total, formatted as seconds), but it also doesn't run the command, instead complaining that it doesn't exist.


Solution

  • You can call /usr/bin/time -p if you want to use this option, or =time -p

    The zsh builtin time doesn't take any option (man zshmisc).

    But you can export TIMEFMT with the format you want, including newlines with \n.

    echo $TIMEFMT to see what it is now