summaryrefslogtreecommitdiffstats
path: root/timer
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-10-05 15:37:45 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-10-05 15:37:45 +0200
commite8fd6dd30401f1ba4d4076ea918ed404894e84f0 (patch)
tree9b9997b1fb0c5a15aece363de90db168b89122e2 /timer
parentc678c9d5d430842ef06f231a4c39b5165f30578a (diff)
downloadbin-e8fd6dd30401f1ba4d4076ea918ed404894e84f0.zip
bin-e8fd6dd30401f1ba4d4076ea918ed404894e84f0.tar.gz
timer: add function timer_dt
Diffstat (limited to 'timer')
-rwxr-xr-xtimer15
1 files changed, 15 insertions, 0 deletions
diff --git a/timer b/timer
index e47bbcb..2436625 100755
--- a/timer
+++ b/timer
@@ -31,6 +31,21 @@ function timer()
fi
}
+function timer_dt()
+{
+ if [[ $# -eq 0 ]]; then
+ echo $(date '+%s')
+ else
+ local stime=$1
+ etime=$(date '+%s')
+
+ if [[ -z "$stime" ]]; then stime=$etime; fi
+
+ dt=$((etime - stime))
+ printf '%d' $dt
+ fi
+}
+
# If invoked directly run test code.
if [[ $(basename $0 .sh) == 'timer' ]]; then
t=$(timer)