转载
https://blog.csdn.net/gengshenghong/article/details/7583580
背景
获取Shell脚本的运行时长
代码
function getTime() {
start=$1
end=$2
echo $start
echo $end
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)
echo "This is only a test to get a ms level time duration..."
end=$(date +%s.%N)
getTime $start $end