Think before you speak, read before you think.

time命令

time命令用于计算一个命令执行的时间

例如sleep 2运行时间是2秒钟

/usr/bin/time sleep 2
0.00user 0.00system 0:02.00elapsed 0%CPU (0avgtext+0avgdata 2656maxresident)k
0inputs+0outputs (0major+211minor)pagefaults 0swaps

time后面可以加很多参数,如-o output.txt将结果输出到文件

/usr/bin/time -o output.txt sleep 2

-f “%P” command 可以按需求输出cpu使用率

/usr/bin/time -f "%P cpu percentage" find ./ -name abc

 -f “%M” command 可以按需求输出内存使用率,

/usr/bin/time -f "%M Max Resident Set Size (Kb)" find ./ -name abc

-f “%e” command 按秒输出命令执行的时间

/usr/bin/time -f "%e running time (sec)" find ./ -name abc

参考

12 UNIX / Linux Time Command Output Format Option Examples


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *