bash shell script 高精度時間測量範例

2017/07/15 shell script 共 474 字,約 2 分鐘

想測量傳輸效能,檔案傳輸完後程式不會結束,改用diff比對

使用time只能取到秒,改用date可以取到ns

#!/usr/bin/env bash

function waitTransfer()
{
    while true
    do
        diff -r --binary --brief $1 $1_dest
        if [ $? -eq 0 ]; then
            break
        fi
        sleep 0.01
    done
}

SIZE_TYPE='file1M file5M file50M'
for sizeType in $SIZE_TYPE
do
    mkdir ${sizeType}_dest
    echo 'Run  --- ' $sizeType

    begin=$(date +%s%N)


    # do Something

    waitTransfer $sizeType


    end=$(date +%s%N)
    elapsed=$((end - begin))
    echo 'Done --- ' $sizeType
    bc -l <<< "$elapsed / 1000000000"

    echo "======================"
    rm -rf ${sizeType}_dest
done


exit

文章訊息

Search

    Table of Contents