summaryrefslogtreecommitdiffstats
path: root/util/bin/timer
blob: 98c43063f4a8fff2488a48edc901aba26aef0053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

if [[ $# -eq 0 ]];then
  echo $(date '+%s')
else
  [ "$1" -eq "-h" -o "$1" -eq "--help" ] && \
    echo "usage: $0 [start_time]" && \
    echo "  if no start_time is given, return the currentime" && \
    echo "  if start_time is given, return the difference"
  stime=$1
  etime=$(date '+%s')
  [[ -z "$stime" ]] && stime=$etime
  echo $((etime - stime))
fi