Measure code execution time php code example

Example 1: php check how much time each instruction takes to complete

$start = microtime(true);
while (...) {

}
$time_elapsed_secs = microtime(true) - $start;

Example 2: php set time counters inside code meassure

<?php
//No need for microtime at the start of script.

// Use this at the end of your script, or around in the 
// code where you need to take meassures.
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];

echo "Did stuff in $time seconds\n";
?>

Tags:

Php Example