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 

  

posted on 2022-07-21 17:54  DuoRuaiMi4567  阅读(95)  评论(0编辑  收藏  举报