Alexander Mills Alexander Mills - 1 year ago 83
Bash Question

Get time diff in tenths of seconds

Just trying to keep track of the build time for a bash script, to the 1/10th of a second

I am looking for something like:

sleep 5;

and round it to a tenth of a second.

How can I do this?

123 123
Answer Source

You can use date with nanosecond and truncate to one char


START=$(date "+%s%1N")
sleep 2
END=$(date "+%s%1N")

echo "The difference is $((END-START))"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download