PHP program to compute the execution time of a PHP script

PHPServer Side ProgrammingProgramming

To compute the execution time of a PHP script, the code is as follows −

Example

 Live Demo

<?php
$start = microtime(true);
$val=1;
for($i = 1; $i <=1500; $i++)
{
   $val++;
}
$end = microtime(true);
$exec_time = ($end - $start);
echo "The execution time of the PHP script is : ".$exec_time." sec";
?>

Output

The execution time of the PHP script is : 1.69 sec

The ‘microtime’ function can be used to check the time taken by a PHP script to execute completely. When the code begins execution, the time is recorded, and once the code is completed, another timestamp is generated and the difference between the end and star time is the time taken by the script to complete its execution.

raja
Published on 02-Jul-2020 10:21:19
Advertisements