Calculate Script Execution Time
Calculate how long it takes to execute a script in PHP. Place a variable $time_start at the beginning of the script to get a start time. Place a print statement at the end of the script which displays the difference between the end and start of the script in microseconds.
<?php
$time_start = microtime(true); // place at start of script
/*
- script goes here -
*/
print "<hr><p>Execution time: " . (microtime(true) - $time_start) . " microseconds.</p>"; // end of script
?>
Example:
PHP
<?php $time_start = microtime(true); // place at start of script for ($i=0; $i<count($array); $i++) { calculate($stuff); calculatemore($stuff); } print "<hr><p>Execution time: " . (microtime(true) - $time_start) . " microseconds.</p>"; // end of script ?>
Produces the result:
Execution time: 4.8610229492 microseconds.