【问题标题】:Get the wall time in seconds using a linux command?使用 linux 命令以秒为单位获取挂墙时间?
【发布时间】:2018-03-03 05:20:05
【问题描述】:

如何使用 linux 命令获取执行程序所花费的挂墙时间(以秒为单位)。在下面的示例中,我预计会得到“0.005”。

$ time ls >/dev/null

real    0m0.005s
user    0m0.001s
sys 0m0.003s

【问题讨论】:

    标签: linux time


    【解决方案1】:

    取决于你的路径:

    /usr/bin/time -f "%e"
    

    正常时间由 bash 的(如果你碰巧使用 bash)实习时间命令给出

    type time
    

    当你需要的时候,

    which time
    

    会找到的。

    所以在你的命令上下文中:

    /usr/bin/time -f "%e" ls > /dev/null
    

    但要将其存储在变量中,则不能使用

    a=$(/usr/bin/time -f "%e" ls > /dev/null)
    

    因为时间的输出被写入错误流,不影响程序输出(在这个例子中ls)。有关详细信息,请参阅time 的联机帮助页。

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 2022-11-28
      • 2011-04-30
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2016-08-03
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多