Measure execution times of php scripts

Measure execution times of php scripts
5 (100%) 1 vote

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." ";
}
sleep(1);
// 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 *