如何在嵌套命令上使用time命令?

时间:2014-05-01 05:12:16

标签: linux bash shell time

我需要使用GNU time命令来测量我编写的程序,所以我 试图

/usr/bin/time -v cat test/testin | ./db retrieve >> test/result

但输出中的第一行显示

Command being timed: "cat test/testin"

用户时间和系统时间

User time (seconds): 0.00
System time (seconds): 0.02
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 2:02.73

表明自从这个程序以来我没有计算我的程序使用的时间 应该在CPU使用率相当的情况下运行2分钟或更长时间。

2 个答案:

答案 0 :(得分:3)

在您的情况下,您可以简单地省略UUOC。在一般情况下,你可以做

time sh -c "cmd | cmd"

答案 1 :(得分:2)

/usr/bin/time -v ./db retrieve < test/testin >> test/result

Useless use of cat