linux计算命令的执行时间

有时候为了达到同一结果,但有多种不同的办法能够执行,因此想要了解不同命令执行,哪个使用CPU、内存、时间最少

实现方法

time #time 后面直接跟命令即可
-v: 显示更加详细信息

示例

  1. 统计运行时间
]# time touch {1..100}.txt

  1. 统计运行时间结果重定向-使用子shell"() &>/path/to/info.txt"
]# (time for i in `ls /data/images/`;do find /data -type f -name "$i"|xargs rm -f;done) &> /data/info.txt
]# cat /data/info.txt

real	0m0.194s
user	0m0.033s
sys	0m0.158s

  1. 统计运行时间结果重定向-使用"{ time <command>; } &>/path/to/info.txt"

注意花括号中的空格和分号

]# { time find ./ -name "*.txt" ;} &>/data/info.txt
]# cat /data/info.txt
... #省略
./99.txt
./100.txt

real	0m0.001s
user	0m0.001s
sys	0m0.000s

原文地址:https://www.cnblogs.com/wanwz/p/12808909.html