1

When I run the time command in shell time ./myapp I get an output like the following:

real 0m0.668s

user 0m0.112s

sys 0m0.028s

However,when I run the command \time -f %e ./myapp I lose precision and I get:

2.01s

Why is the output not with 3 digits of precision as well? If I use the %E command I also lose precision in the same way. How do i change it to have more precision again, but still only have the seconds being outputted?

I based my research in this Linux / Unix Command: time

4

2 回答 2

2

You can try /usr/bin/time -p instead. The -p option should display the output in the standard format. Here's an example from my MacBook:

gondolin% /usr/bin/time find . -name '*.pyc' > /dev/null
        0.10 real         0.04 user         0.05 sys
gondolin% /usr/bin/time -p find . -name '*.pyc' > /dev/null
real         0.10
user         0.04
sys          0.05

According to die.net, then time utility should allow you to specify the format in the TIME environment variable. The bash builtin does something similar but uses the TIMEFORMAT environment variable instead:

bash-3.2$ time find . -name '*.pyc' > /dev/null

real        0m0.155s
user        0m0.051s
sys         0m0.068s
bash-3.2$ export TIMEFORMAT='real    %R
user    %U
sys     %S'
bash-3.2$ time find . -name '*.pyc' > /dev/null
real    0.107
user    0.049
sys     0.058
bash-3.2$ 
于 2013-03-31T00:37:46.470 回答
0

After asking in other forums, one of them gave me the answer I was looking for. It can be found in here.

于 2013-03-31T11:51:23.233 回答