I've checked this, but the solution provided did not work for me.
Using date I can get the execution time in seconds:
T="$(date +%s)"
#some work here
T="$(($(date +%s)-T))"
echo "execution time (secs) ${T}"
However, when I try this:
T="$(date +%s%N)"
#some work here
T="$(($(date +%s%N)-T))"
Adding %N (as above) to the date to get the nano-second precision I get the following error: -bash: 1369320760N: value too great for base (error token is "1369320760N")
Does anyone know how to measure the execution time in milliseconds using bash under Mac OS X?
# some work here
ommited, I get times from 0.2 to 0.3 sec -- what should be zero (or at least constant) to reach your goal. Whereas/usr/bin/time usleep 50000
gives a reasonale stable time of 0.05 +/- 0.01 sec. (Only tested in Linux, don't know if /usr/bin/time and/or usleep is available on OSX.)