how can i measure the accurate run time of a program by writing a shell script? Like I want to use some for loop and run some samples and then i want to subtract the end_time-start_time to get the duration and thereby average.
If you want more user friendly "time" instead of system & user times..
# do something
# start your script work here
ls -R /etc > /tmp/x
rm -f /tmp/x
# your logic ends here
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
>> The time command has much finer resolution than 1 second
That's why I say "if you want..."
>> ..and its output can be formatted (in bash) ...
I checked the man page of time, looks like you can do it without the variable (which would affect the whole shell). There are some params it takes for formatting.