#[Bash] Duration execution script # #!/bin/bash # Stats run script function time_executiom_script() { echo "This script took $SECONDS seconds to execute" } # your function / stuff here time_executiom_script ########################################################## #!/bin/bash # your function / stuff here format_time() { ((h=${1}/3600)) ((m=(${1}%3600)/60)) ((s=${1}%60)) printf "%02d:%02d:%02d\n" $h $m $s } echo "Script completed in $(format_time $SECONDS)" ########################################################## #!/bin/bash START1="$(date +%s)" sleep 2 END1="$(date +%s)" sleep 2 START2="$(date +%s)" sleep 3 END2="$(date +%s)" DURATION1=$[ ${END1} - ${START1} ] DURATION2=$[ ${END2} - ${START2} ] echo "The 1st part of the code took: ${DURATION1}" echo "The 2nd part of the code took: ${DURATION2}" ########################################################## #!/bin/bash my_sleep_function(){ sleep 1 } OVERALL_START="$(date +%s)" FUNCTION_START="$(date +%s)" my_sleep_function FUNCTION_END="$(date +%s)" sleep 2 OVERALL_END="$(date +%s)" echo "The function part of the code took: $[ ${FUNCTION_END} - ${FUNCTION_START} ] seconds to run" echo "The overall code took: $[ ${OVERALL_END} - ${OVERALL_START} ] seconds to run"