Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active March 28, 2023 23:39
Show Gist options
  • Save ramiabraham/e9793ead983a963e1806ce73bb50c434 to your computer and use it in GitHub Desktop.
Save ramiabraham/e9793ead983a963e1806ce73bb50c434 to your computer and use it in GitHub Desktop.
Determines the amount of execution time for a process.
# Output in minutes:
START=$(date +%s)
END=$(date +%s)
DIFF=$(( $END - $START ))
DIFF=$(( $DIFF / 60 ))
echo DIFF
# Full output:
res1=$(date +%s.%N)
# do stuff in here
res2=$(date +%s.%N)
dt=$(echo "$res2 - $res1" | bc)
dd=$(echo "$dt/86400" | bc)
dt2=$(echo "$dt-86400*$dd" | bc)
dh=$(echo "$dt2/3600" | bc)
dt3=$(echo "$dt2-3600*$dh" | bc)
dm=$(echo "$dt3/60" | bc)
ds=$(echo "$dt3-60*$dm" | bc)
printf "Total runtime: %d:%02d:%02d:%02.4f\n" $dd $dh $dm $ds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment