I have the following code to calculate the execution time.
$TimeTaken['start'] = microtime();
require_once 'resources/include.php';
session_start();
ob_start();
error_reporting(E_ALL);*/
error_reporting(0);
/* Other Mojo
...............
...............
...............
*/
ob_flush();
flush();
ob_end_flush();
$TimeTaken['end'] = microtime();
$TimeTaken['diff'] = $TimeTaken['end'] - $TimeTaken['start'];
print_r($TimeTaken);
?>
This is the output that i got (sometimes)
Array ( [start] => 0.72150600 1329728036
[end] => 0.62957200 1329728038
[diff] => -0.091934 )
Is the above code right and if so why is start time > end time
Because the valid way to get the time with microseconds is
microtime(true);, notmicrotime();Without second parameter equal to
trueyou just have a string0.72150600 1329728036that represents the second fractions and seconds since unix epoch separated by space. And subtraction operator just casts it to the0.72150600which is just wrong.