First method
$start = microtime(true);
// code
$end = microtime(true);
echo 'This page loaded in '.round($end - $start, 4).' sec';
Second method
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
// code
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'This page loaded in '.$total_time.' sec';
What is the difference between them and which one is better ? And also do you have other suggestions?
The main difference is that the first example will not work on PHP4 while the second one will (see the changelog part of the manual). If your code not expected to run on PHP4 (no new code should be in my opinion) then you can use the first one which is marginally faster since it does less.