Core code
<?php class
timer//page execution time class
{
var starttime;//page start execution time
var stoptime;//page End Execution Time
var spendtime ;//page execution takes time
function getmicrotime ()//Gets the floating-point number
{
list (usec,sec) =explode ("", Microtime ())
that returns the current microseconds. Return ((float) usec + (float) sec);
The function start ()//page begins executing functions, returning the Start page execution time
{
this->starttime=this->getmicrotime ();
}
function display ()//Displays the time of the page execution
{
this->stoptime=this->getmicrotime ();
this->spendtime=this->stoptime-this->starttime;
Return round (this->spendtime,10);
}
/* Call method
timer=new timer ();
Timer->start ();
/* Place the script you want to execute or code for
(i=0;i<100000;i++)
{
echo i;
echo "<br>";
}
* * *
//echo "<p> takes time to execute this code." Timer->display (). " Seconds ";
? >
PHP detects every piece of code execution time
<?php
//instance 1
/**
* @start time
/
function Prostarttime () {
global $startTime;
$mtime 1 = Explode ("", Microtime ());
$startTime = $mtime 1[1] + $mtime 1[0];
}
/**
* @End time
/function Proendtime () {
global $startTime, $set;
$mtime 2 = Explode ("", Microtime ());
$endtime = $mtime 2[1] + $mtime 2[0];
$totaltime = ($endtime-$startTime);
$totaltime = Number_format ($totaltime, 7);
echo "<br/>process time:". $totaltime;
}
Prostarttime () When the program call begins to be recorded
;
Sleep (1); Sleep () Delay code executes several seconds
proendtime ();//The Execution time of the program is consumed in each paragraph
(2);
Proendtime ();
Sleep (3);
Proendtime ();
/************************************************* Gorgeous split line **************************************************/
Instance 2
$t 1 = microtime (true);
Sleep (3);
$t 2 = Microtime (true);
Echo ' Program time consuming '. Round ($t 2-$t 1,3). ' Seconds ';
? >