I need to execute a curl command inside a for loop multiple times, and get the average time it took to execute a single curl. This is what I have:
while read query; do
TIMEFORMAT=%R; time for i in {1..3}; do curl -s -w '\n' -XPOST -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode query='${query}' ${nginx_url} > /dev/null; done
done < queries.txt
This prints the number of seconds in stdout, but I need to assign that number to a variable to divide it by 3 in order to get the average.
I have tested with:
realtime=$(time -f "%E" for i in {1..3} ..etc..)
realtime=`time -f "%E" for i in {1..3} ..etc..`
But this gives syntax error ./test-suite.sh: line 23: syntax error near unexpected tokendo'.
I have also tested with:
realtime=$(bash -c "TIMEFORMAT=%R; time for i in {1..3} ..etc..")
realtime=$(bash -c "time -f "%E" for i in {1..3} ..etc..")
realtime=$(bash -c "TIMEFORMAT=%R; time for i in {1..3} do ..etc.. ; done; echo $realtime")
All of them bear no results. Any ideas are welcome.
/usr/bin/time. You're using bash'stimekeyword.