Home >Backend Development >PHP Tutorial >PHP calculation script execution time class php script parameters php script execution how to run php script

PHP calculation script execution time class php script parameters php script execution how to run php script

WBOY
WBOYOriginal
2016-07-29 08:54:581059browse

1. When optimizing code, the execution time of the script is a very important consideration. So how to use PHP to calculate the running time of the PHP script?

The following is a useful class recommended for everyone.

runtime.class.php

/**
* PHP script execution time calculation
*/
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
                                                                                                                                            function get_microtime()                                                                         . {
                                                                            use using use using  -                                     $echo=false,$title='')
{
$spent = sprintf('%.4f',round(($this->StopTime - $this->StartTime) * 1000, 1)/1000) ; If ($ echo) {
echo $ table. "Execution time: {$ Spent} second & lt; br/& gt;";
} else {
Return $ spent;
                $this->StartTime = 0;
                  $this->StopTime = 0;
                                 ‐         ‐              );
$a = 0;
for($i=0; $i<100000; $i++)
{
$a *= $i;
}
$runtime->stop();
$spent_time = $runtime->spent($echo=true, 'test script');
$runtime->clear();


Test results:





The above introduces the PHP script execution time calculation class, including PHP and script content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn