Measure execution times of php scripts

For this we will use microtime() function — Return current Unix timestamp with microseconds.

//Start calculating the time
$time_start = microtime(true);
for($i=0; $i< 1000; $i++){
echo $i." ";
// Finish time calculation
$time_end = microtime(true);
$time = $time_end - $time_start;
// Display script time
echo "</br>The script ran into $time microseconds";

//Result: The script ran into 1.0140018463135 microseconds

Leave a Reply

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