bash shell计算时间差
作者:互联网
function getTiming() { start=$1 end=$2 start_s=$(echo $start | cut -d '.' -f 1) start_ns=$(echo $start | cut -d '.' -f 2) end_s=$(echo $end | cut -d '.' -f 1) end_ns=$(echo $end | cut -d '.' -f 2) time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) )) echo "$time ms" } start=$(date +%s.%N) end=$(date +%s.%N) runtime=$(getTiming $start $end) echo "runtime: "$runtime
标签:10,shell,end,ns,echo,start,cut,时间差,bash 来源: https://www.cnblogs.com/duoruaimi4/p/16502902.html