17

The time only print the the execution second time of a command.

If there is a solution like IPython's powerful timeit magic command, great.

2 Answers 2

27

zsh's time uses the TIMEFMT variable to control the format. By default, this is %J %U user %S system %P cpu %*E total, which produces the following.

$ time sleep 2
sleep 2 0.00s user 0.00s system 0% cpu 2.002 total

This does produce millisecond accuracy (at least for total), so perhaps your system has a different default set (lagging distro?), or has modified TIMEFMT.

Have a look at the manual page for possible formats. I use the following in ~/.zshrc:

TIMEFMT=$'\n================\nCPU\t%P\nuser\t%*U\nsystem\t%*S\ntotal\t%*E'

which produces the following.

$ time sleep 2 

================
CPU     0%
user    0.003
system  0.000
total   2.006
2

The ipython timeit magic command will by default print a statistics report over several executions of your statement. The zsh reserved word time will only run your command once.

When you only care about measuring the execution time of external commands (and not builtins and functions) you can use hyperfine. It's a program that repeatedly executes a command for you and prints some statistics.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .