linux程序运行耗时shell脚本running_time.sh
生活随笔
收集整理的這篇文章主要介紹了
linux程序运行耗时shell脚本running_time.sh
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對一個程序進行多次運行,求其平均運行時間
function timediff() {# time format:date +"%s.%N", such as 1502758855.907197692start_time=$1end_time=$2start_s=${start_time%.*}start_nanos=${start_time#*.}end_s=${end_time%.*}end_nanos=${end_time#*.}# end_nanos > start_nanos? # Another way, the time part may start with 0, which means# it will be regarded as oct format, use "10#" to ensure# calculateing with decimalif [ "$end_nanos" -lt "$start_nanos" ];thenend_s=$(( 10#$end_s - 1 ))end_nanos=$(( 10#$end_nanos + 10**9 ))fi# get timedifftime=$(( 10#$end_s - 10#$start_s )).$(( (10#$end_nanos - 10#$start_nanos)/10**6 ))avgtime=`echo "sclae=4; $time/$n" | bc -l`echo $avgtime }starttime=`date +'%s.%N'`i=0 n=5 while [ $i -lt 5 ] #循環,把兩個5改成想要運行的次數 do./a.out big quicksort1_opti2 #需要運行的程序waitlet i=i+1 done wait # 等待執行完成 即可 endtime=`date +'%s.%N'`echo "程序平均運行時間: " timediff $starttime $endtime #比較開始和結束時間的差 echo " s" exit 0./running_time.sh >> result.txt
可以使結果寫入文本中
nohup ./running_time.sh >> result.txt &
轉入后臺運行,終端可以繼續干別的
jobs
命令查看后臺程序
- -u 不緩存,實時輸出到 out 文件
- >> 追加, > 覆蓋
總結
以上是生活随笔為你收集整理的linux程序运行耗时shell脚本running_time.sh的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python scipy库函数solve
- 下一篇: eplise怎么连接数据库_eclips