From e8fd6dd30401f1ba4d4076ea918ed404894e84f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 5 Oct 2012 15:37:45 +0200 Subject: timer: add function timer_dt --- timer | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) -- cgit v1.1-2-g2b99