封装程序的运行时间计算函数
<?php
function runtime($start = null , $end = null){
static $cache = [];
if(is_null($start)){
return $cache;
}elseif(is_null($end)){
return $cache[$start] = microtime(true);
}else{
$end = $cache[$end] ?? microtime(true);
return round($end - $cache[$start],1);
}
}
echo runtime('for');
echo '<hr/>';
for($i = 0 ; $i<= 200000000;$i++){
}
echo '<hr/>';
echo runtime('forEnd');
echo '<hr/>';
echo 'for循环的总时间:' . runtime('for','forEnd');