How to find execution time in php


For every project we will check performance of execution..In order to check performance first and foremost thing we do is..checking execution time..right?

Now lets see how can we write a script to check execution time..

Basically we will use microtime() function to calculate execution time..

At starting of execution we will call microtime() and ending of script also we will call microtime()..Now we will calculate endtime-starttime to get execution time..for more clickhere


$time_start = microtime(true);

// Sleep for a while


//your code here

$time_end = microtime(true);
$time = $time_end – $time_start;

echo “Did nothing in $time seconds\n”;


* Simple function to replicate PHP 5 behaviour
function microtime_float()
list($usec, $sec) = explode(” “, microtime());
return ((float)$usec + (float)$sec);

$time_start = microtime_float();

// Sleep for a while
usleep(100);        (or)  //your code here

$time_end = microtime_float();
$time = $time_end – $time_start;

echo “Did nothing in $time seconds\n”;

with this you can display execution time in seconds..if you want to display in mins..just add “$min = $time/60;” and echo $min.

Thats are done with your code now 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s