是否可以使用以下组合打印shell命令的执行时间?
root@hostname:~# "command to execute" && echo "execution time"
发布于 2009-11-01 13:02:46
time
是大多数shells中的内置命令,用于将执行时间信息写入tty。
你也可以尝试像这样的东西
start_time=`date +%s`
<command-to-execute>
end_time=`date +%s`
echo execution time was `expr $end_time - $start_time` s.
或在bash
中
start_time=`date +%s`
<command-to-execute> && echo run time is $(expr `date +%s` - $start_time) s
发布于 2009-11-01 12:53:40
root@hostname:~# time [command]
它还区分了使用的实时时间和使用的系统时间。
发布于 2015-01-30 02:30:57
补充@mob的答案:
将%N
附加到date +%s
后,我们可以获得纳秒精度:
start=`date +%s%N`;<command>;end=`date +%s%N`;echo `expr $end - $start`
https://stackoverflow.com/questions/1656425
复制相似问题