I've seen several questions on this topic, all with the same basic answer. Use microtime() to record the start and end time, then subtract. Mostly this works, except when the event spans the point where the seconds are incremented. At that point the end time may be less than the start time.
Can you use a function to add seconds to the microtime() to get seconds + microtime?
Example:
function getSMtime() {
return time() + (microtime() / 1000000);
}
$start = getSMtime();
... some code to be timed ...
$end = getSMtime();
echo "Time elapsed: " . ($end - $start) . " seconds.";