<?php
//Life is a class that calculates the running time of a script
class Timer{
private $startTime = 0; //Save the time when the script starts executing (save in microseconds)
private $stopTime = 0; //Save the time when the script ends execution (save in microseconds)
//Call at the script start to get the microsecond value of the script start time
function start(){
$this->startTime = microtime(true); // Assign the obtained time to the member attribute $startTime
}
//Microsecond value of the end of the script at the end of the script
function stop(){
$this->stopTime = microtime(true); // Assign the obtained time to the member attribute $stopTime
}
//Return the difference in the time obtained twice in the same script
function spent(){
//After calculation, 4 round 5, reserve 4 bits to return
return round(($this->stopTime-$this->startTime),4);
}
}
$timer= new Timer();
$timer->start(); //Call this method when the script file starts executing
usleep(1000); //The theme content of the script, here you can sleep for one millisecond as an example
$timer->stop(); //Call this method at the end of the script file
echo "Time to execute the script<b>".$timer->spent()."</b>";
?>