How to time processes in milliseconds from terminal

Post date: Jul 5, 2016 9:11:32 PM

This is the solution I have been using here in this example on my EC2 Linux machine:

Measuring milliseconds elapsed in shell scripts

This example time the latency occurred in each API call.

> STARTTIME=`date +%s.%N`; curl -d "{\"property_id\": 4503841, \"num\": 30}" -H "x-api-key: <API key>" -s https://BKJGJKHBSD.execute-api.us-west-2.amazonaws.com/prod/GetNearbyPropertiesByPid; ENDTIME=`date +%s.%N`; TIMEDIFF=`echo "$ENDTIME - $STARTTIME" | bc | awk -F"." '{print $1"."substr($2,1,3)}'`; echo "   $TIMEDIFF"
> STARTTIME=`date +%s.%N`; curl -d "{\"property_id\": 99038733, \"num\": 10}" -H "x-api-key: <API key>" -s https://BKJGJKHBSD.execute-api.us-west-2.amazonaws.com/prod/GetNearbyPropertiesByPid; ENDTIME=`date +%s.%N`; TIMEDIFF=`echo "$ENDTIME - $STARTTIME" | bc | awk -F"." '{print $1"."substr($2,1,3)}'`; echo "   $TIMEDIFF"
> STARTTIME=`date +%s.%N`; curl -d "{\"property_id\": 97500918, \"num\": 5}" -H "x-api-key: <API key>" -s https://BKJGJKHBSD.execute-api.us-west-2.amazonaws.com/prod/GetNearbyPropertiesByPid; ENDTIME=`date +%s.%N`; TIMEDIFF=`echo "$ENDTIME - $STARTTIME" | bc | awk -F"." '{print $1"."substr($2,1,3)}'`; echo "   $TIMEDIFF"

Further resources:

What do 'real', 'user' and 'sys' mean in the output of time?

how-to-get-execution-time-of-a-script-effectively

linux-command-to-get-time-in-milliseconds