#!/bin/sh
# execute a command, getting execution time
# [ use /proc/rtc real-time support in the kernel]
# (C) M. Andreoli for muLinux

#set -x

[ -f /proc/rtc ] || (echo "no rtc support in the kernel, abort" ; exit 1)

get_time()
{
set -- $(cat /proc/rtc| rgrep rtc_time)
now=$3
save=$IFS; IFS=":"
set -- $now
h=$1; m=$2; s=$3
IFS=$save

t=`expr $h \* 3600`
t=$( expr $t + `expr $m \* 60` )
t=$( expr $t + $s )
echo $t
}

# Main

case Z$1 in
Z|Z-h)
	echo "(rustic) timex: execution time of a command."
	echo "Usage: timex command parameters ..."
	exit 0
	;;
esac


start=`get_time`
eval $@
end=`get_time`
echo 
echo "-- Execution time: `expr $end - $start`s"

# End


