0

hi,
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.

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by thekashyap
0

Googled:

If you want more user friendly "time" instead of system & user times..

#!/bin/bash
START=$(date +%s)
# do something

# start your script work here
ls -R /etc > /tmp/x
rm -f /tmp/x
# your logic ends here

END=$(date +%s)
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
0

If you want more user friendly "time" instead of system & user times..


The time command has much finer resolution than 1 second, and its output can be formatted (in bash) using the TIMEFORMAT variable.

0

>> 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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.