#!/bin/bash
start=$(date +%s.%N)
# HERE BE CODE
end=$(date +%s.%N)
runtime=$(python -c "print (${end} - ${start})")
echo "Runtime was $runtime"
Yes, this calls Python, but if you can live with that then this is quite a nice, terse solution I use.