PHP : Find script execution time

If you are a PHP developer chances are many that you need to find how much time it took to execute a piece of code. Using the script below you can find how much time it took to execute your php code.


$time_start = microtime(true);

// execute your tasks here

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

echo "Code executed in $time seconds\n";

You can try these examples


$time_start = microtime(true);

// execute your tasks here
phpinfo();

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

echo "Code executed in $time seconds\n";

Another example


$time_start = microtime(true);

// execute your tasks here
sleep(1); // wait for 1 second

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

echo "Code executed in $time seconds\n";

ASP and C# version of the code can be found here

Check Javascript version here

This entry was posted in PHP and tagged . Bookmark the permalink.

3 Responses to PHP : Find script execution time

  1. Pingback: Javascript : Find script execution time | eInternals

  2. Pingback: VBScript : Find script execution time | eInternals

  3. Pingback: ActionScript : Find code execution time | eInternals

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>