我该如何在Mac OS X的shell脚本中以毫秒为单位测量经过的时间?
您可以使用:
start_ms=$(ruby -e 'puts (Time.now.to_f * 1000).to_i')
# do some work
end_ms=$(ruby -e 'puts (Time.now.to_f * 1000).to_i')
elapsed_ms=$((end_ms - start_ms))
echo "$elapsed_ms ms passed"
或者仅使用shell内置命令(在bash和zsh中都适用):
start_ns=$(date +%s%N)
# do some work
end_ns=$(date +%s%N)
elapsed_ms=$(((end_ns - start_ns) / 1000000))
START=$(date +%s)
//you script like flutter build ipa
END=$(date +%s)
DIFF=$(echo "$END - $START" | bc)
echo "whole process finished in $DIFF seconds"