【问题标题】:Gnu time and formatting outputGnu 时间和格式化输出
【发布时间】:2012-03-15 07:35:20
【问题描述】:

我想使用 gnu time 来测量一些小的 .c 程序的运行时间。在男人中写道:

-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

我想知道问题出在哪里,我在哪里犯了错误?我只是想向用户显示时间,这就是我玩弄时间输出格式的原因。

【问题讨论】:

    标签: linux gnu


    【解决方案1】:

    Bash for one 有一个名为 time 的内置 shell。克服它的一种方法是输入command time - 命令将忽略内置程序并从您的$PATH 运行time 程序。另一种方式是alias time=/usr/bin/time。另一方面,bash 内置尊重环境变量TIMEFORMAT

    【讨论】:

    • 感谢您的快速回答,我将只使用 TIMEFORMAT,但所有这些都有效。
    • /usr/bin/time 在某些系统(例如 NixOS)上不可用,但我发现 command time ... 可以作为避免内置 bash 的一种方式。
    • 好点,command 是一个 POSIX 定义的 shell 实用程序,所以它应该可以在sh 和任何可以充当@987654334 的东西(包括bashksh)中使用@。正如这里提到的:stackoverflow.com/questions/6365795/…
    猜你喜欢
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    相关资源
    最近更新 更多