I wish to find out how long an operation takes in a Linux shell script. How can I do this?
Here is the script to find the time elapsed in milliseconds. Replace the sleep 60 line with the code you want to execute.
a=0
while [ $a -lt 10 ]
do
START_TIME=`echo $(($(date +%s%N)/1000000))`
sleep 3
END_TIME=`echo $(($(date +%s%N)/1000000))`
ELAPSED_TIME=$(($END_TIME - $START_TIME))
echo $ELAPSED_TIME
if [ $a -eq 10 ]
then
break
fi
a=`expr $a + 1`
done