How can I measure the runtime of my script which is like this :
#! /bin/bash
start1=`date +%s`
./a &
./a &
./a &
./a &
./a &
end=`date +%s`
runtime=$((end-start1))
echo "$runtime"
the measured time is 0 because all the command run in background and at the same time what should I do?
Use the wait
command to wait for the processes to finish, before measuring the time
#! /bin/bash
start1=`date +%s`
./a &
./a &
./a &
./a &
./a &
wait # <----------------
end=`date +%s`
runtime=$((end-start1))
echo "$runtime"
You can also use the time
command for better and more accurate results:
time {
./a &
./a &
./a &
./a &
./a &
wait # <----------------
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With