How do I run 100 iterations using a bash shell script? I want to know how long it will take to execute one command (start and end time). I want to keep track which iteratio
You can try with:
for i in {1..100}; do time some_script.sh; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'
timetime so we can grep itgrep ^real is to get only the lines starting with "real" in the output of timesed is to delete the beginning of the line up to minutes part (in the output of time)awk adds to the sum, so that in the end it can output the average, which is the total sum, divided by the number of input records (= NR)The snippet assumes that the running time of some_script.sh is less than 1 minute, otherwise it won't work at all. Depending on your system, the time builtin might work differently. Another alternative is to use the time command /usr/bin/time instead of the bash builtin.
Note: This script was extracted from here.