差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
linux:shell_script:execution_time_measurement [2016/07/02 11:12]
tony
linux:shell_script:execution_time_measurement [2023/06/25 09:48] (目前版本)
行 1: 行 1:
 +{{tag>​Linux ShellScript}}
 ====== 測量執行時間 ====== ====== 測量執行時間 ======
 ===== time command ===== ===== time command =====
行 22: 行 23:
  
 echo $END echo $END
 +</​code>​
 +===== date command =====
 +與$SECONDS方法類似,但可以精確到nano second(10^-9)的差距:​
 +<code bash>
 +START=`date +%s%N`
 +echo $START
 +
 +# some operations
 +sleep 1
 +
 +END=`date +%s%N`
 +echo $END
 +
 +END=$(($END - $START))
 +echo $END
 +
 +# 換算為millisecond
 +END=$(($END / 1000000))
 +echo $END
 +</​code>​
 +
 +output:
 +
 +<code bash>
 +1467450293336690574
 +1467450294338625297
 +1001934723
 +1001
 </​code>​ </​code>​
 ===== Reference ===== ===== Reference =====
   * [[http://​www.livefirelabs.com/​unix_tip_trick_shell_script/​oct_2003/​10272003.htm|Useful Shell Script Variables - Part V - SECONDS]]   * [[http://​www.livefirelabs.com/​unix_tip_trick_shell_script/​oct_2003/​10272003.htm|Useful Shell Script Variables - Part V - SECONDS]]
 +  * [[http://​stackoverflow.com/​questions/​16548528/​linux-command-to-get-time-in-milliseconds#​comment57307577_16548528|Linux command to get time in milliseconds]]
  
 =====    ===== =====    =====