Compute Execution Time of a PHP Script



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.

Updated on: 2020-07-02T06:51:46+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements