日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux程序运行耗时shell脚本running_time.sh

發布時間:2024/7/5 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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
命令查看后臺程序

nohup python -u TargetRecongnizer-pt.py > out 2>&1 &
  • -u 不緩存,實時輸出到 out 文件
  • >> 追加, > 覆蓋

總結

以上是生活随笔為你收集整理的linux程序运行耗时shell脚本running_time.sh的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。