#!/bin/bash

# Normally we would just do something like...
#   time "Importing $(notdir $<) took %E" <cmd>
# ...but it doesn't properly buffer output which causes tearing in the log, so
# we roll our own cheap and cheerful process timing.

label_text=$1

shift

timestamp_0=`date +%s`
$@
return_code=$?
timestamp_1=`date +%s`

delta_time=$((timestamp_1-timestamp_0))

if [ $return_code -eq 0 ]; then
  echo $label_text took $delta_time seconds
else
  echo $label_text failed in $delta_time seconds
fi

exit $return_code
