2019年5月23日 星期四

計算命令執行的時間

time

#time ls
folders.txt  PData        RD_Data  UB_packBackup.sh  user.txt
homes        RDBackup.sh  UB_pack  userbackup.sh

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


real:命令開始執行到结束的时间。包含cpu處理時間,系統io的時間等等,一般所指的跑多久,就是指這個時間。
user:cpu花在執行這個程式的時間,The amount of cpu time spent in user mode(outside the kernel).
sys:cpu核心花在執行這個程式的時間,The amount of cpu time spent in the kernel within the process.

重複執行 echo "run test..."' 10次
#time tsch -c 'repeat 10 echo "run test..."'
重複執行 test.sh 10次
#time tsch -c 'repeat 10 file test.sh'

/usr/bin/time
-o 将執行時間寫入指定檔案內
/usr/bin/time -o outfile.txt ls
-a 追加訊息
/usr/bin/time -a -o outfile.txt ls
-f 選擇輸出的時間格式
/usr/bin/time -f "time: %U" ls
%E real time
%U user time
%S sys time