Skip to main content

Determine execution time in PHP

Ref: http://www.developerfusion.com/code/2058/determine-execution-time-in-php/

This code is based on the ASP script posted by Lio. It will determine the time taken for a php script to execute correct to 0.000000000000001 seconds.


<!-- put this at the top of the page -->

<?php

   $mtime = microtime();

   $mtime = explode(" ",$mtime);

   $mtime = $mtime[1] + $mtime[0];

   $starttime = $mtime;

;?>

<!-- put other code and html in here -->

<!-- put this code at the bottom of the page -->
<?php

   $mtime = microtime();

   $mtime = explode(" ",$mtime);

   $mtime = $mtime[1] + $mtime[0];

   $endtime = $mtime;

   $totaltime = ($endtime - $starttime);

   echo "This page was created in ".$totaltime." seconds";

;?>