Created
June 3, 2013 00:32
-
-
Save crazy-max/5695509 to your computer and use it in GitHub Desktop.
Timing a script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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