如何处理时间数据

How to deal with the time data

linux命令代码time <command> | tail -n2,我希望提取系统时间和使用时间的行,但是,我得到如下:

time picat slater-6_sat ver2 "0"

输出是:

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

而当我只输入 picat slater-6_sat ver2 "0"

输出是:

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

我希望输入 time picat slater-6_sat ver2 "0" | tail -n2 ,

输出是:

user    0m0.035s
sys     0m0.019s

然而,事实是:


success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

我猜是处理器认为是时间,所以把picat slater-6_sat ver2 "0"| tail -n2当作命令

我该如何解决这个问题?

你可以试试这样:

(time picat slater-6_sat ver2 "0") > output.txt 2>&1 && tail -2 output.txt

在此处查看类似的答案:

这是一个示例 python 文件:

from time import sleep
for x in range(0,10):
    sleep(0.4)
    print(x)

现在运行文件如下:

$ (time python3 test.py) > output.txt 2>&1 && tail -2 output.txt

user    0m0.026s
sys 0m0.004s

其他资源: