Skip to content

Instantly share code, notes, and snippets.

@crazy-max
Created June 3, 2013 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazy-max/5695509 to your computer and use it in GitHub Desktop.
Save crazy-max/5695509 to your computer and use it in GitHub Desktop.
Timing a script
#! /bin/sh
function formatSeconds() {
local s=${1}
((h=s/3600))
((m=s%3600/60))
((s=s%60))
if [ "${#h}" == 1 ]; then h="0"$h; fi
if [ "${#m}" == 1 ]; then m="0"$m; fi
if [ "${#s}" == 1 ]; then s="0"$s; fi
echo "$h:$m:$s"
}
START=$(awk 'BEGIN{srand();print srand()}')
# Do what you want
echo "Hello world!"
END=$(awk 'BEGIN{srand();print srand()}')
echo "Time spent: `formatSeconds $(($END - $START))`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment