Thursday 15 March 2012

Calculate time taken for execution of php script or web page

Hi,

Often working on a website, it is quite necessary to check the execution speed of the script. As it's the most essential part of a website in terms of user experience that a web page loads as quick as possible.

I used to stuck to such situation, where I want to update my script functionality but not sure how it's gonna affect scripts execution speed. Here is wonderful script that I use to find out how much time it takes to execute the script.

<?php
$curTime = microtime();
$curTime = explode(' ', $curTime);
$strTime = $curTime[1] + $curTime[0];
/********************************************/
/********* PLACE YOUR CODE HERE **********/
/********************************************/ 

$curTime = microtime();
$curTime = explode(' ', $curTime);
$finTime = $curTime[1] + $curTime[0];
$totTime = round(($finTime - $strTime), 6);
echo 'Script took '.$totTime.' seconds to execute.'."\n";
?>

No comments:

Post a Comment