2012-03-15 90 views
12

我想用gnu时间来测量一些小的.c程序的运行时间。在该男子就被写:Gnu时间和格式化输出

-f FORMAT, --format FORMAT 
Use FORMAT as the format string that controls the output of time. See the below more information. 

然后在例子中,我们有:

To run the command `ls -Fs' and show just the user, system, and total time: 
time -f "%E real,%U user,%S sys" ls -Fs 

但是当我尝试发出从例如该命令我得到:

time -f '%E real,%U user,%S sys' ls -Fs 
-f: command not found 

real 0m0.134s 
user 0m0.084s 
sys  0m0.044s 

我想知道问题在哪里,我在哪里犯错?我只是想显示用户时间,这就是为什么我用时间输出格式玩弄。

回答

12

Bash for one有一个shell内建命名为time。其中一种方法是输入/usr/bin/time。另一种方式是alias time=/usr/bin/time。另一方面,bash内建尊重环境变量TIMEFORMAT

+0

感谢您的快速回答,我将只使用TIMEFORMAT,但所有这些工作。 – Andna 2012-03-15 07:53:02

+1

某些系统(例如NixOS)不提供'/ usr/bin/time',但我发现'command time ...'可以避免bash内建。 – Warbo 2017-04-21 22:32:27

+0

好的一点,'command'是一个POSIX定义的shell实用程序,所以它应该在'sh'和任何可以充当'sh'的任何东西(包括'bash'和'ksh')中可用。正如在此提到的:https://stackoverflow.com/questions/6365795/invoking-program-when-a-bash-function-has-the-same-name – minopret 2017-04-25 23:17:07