diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-10-05 15:37:45 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-10-05 15:37:45 +0200 |
commit | e8fd6dd30401f1ba4d4076ea918ed404894e84f0 (patch) | |
tree | 9b9997b1fb0c5a15aece363de90db168b89122e2 | |
parent | c678c9d5d430842ef06f231a4c39b5165f30578a (diff) | |
download | bin-e8fd6dd30401f1ba4d4076ea918ed404894e84f0.zip bin-e8fd6dd30401f1ba4d4076ea918ed404894e84f0.tar.gz |
timer: add function timer_dt
-rwxr-xr-x | timer | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) |