summaryrefslogtreecommitdiffstats
path: root/util/bin/timer
blob: 939c7998eb4876c0d89ebd47a19a901fd1cfcd0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env bash
curr=$(date '+%s%N')
etime=${curr:0:${#curr}-6}
if [[ $# -eq 0 ]];then
  echo $etime
else
  [ "$1" == "-h" -o "$1" == "--help" ] && \
    echo "usage: $0 [start_ms]" && \
    echo "  if no start_ms is given, return the currentime" && \
    echo "  if start_ms is given, return the difference" && exit 0
  stime=$1
  [[ -z "$stime" ]] && stime=$etime
  echo $((etime - stime))
fi