魔法函数执行时间0.635
<?php class Test{ private $var=‘123‘; public function __get($name) { return $this->var; } } function current_time(){ list($usec,$sec)= explode(‘ ‘,microtime()); return ((float)$usec+(float)$sec); } $_start=current_time(); $i=0; while ($i<20000){ $i++; $t=new Test(); $t->var; } $_end=current_time(); header(‘Content-Type:text/html;charset=utf‘); echo ‘执行时间‘.number_format($_end-$_start,3);
public直接获取执行时间为
<?php class Test{ // private $var=‘123‘; public $var=‘123‘; /* public function __get($name) { return $this->var; }*/ } function current_time(){ list($usec,$sec)= explode(‘ ‘,microtime()); return ((float)$usec+(float)$sec); } $_start=current_time(); $i=0; while ($i<20000){ $i++; $t=new Test(); $t->var; } $_end=current_time(); header(‘Content-Type:text/html;charset=utf‘); echo ‘执行时间‘.number_format($_end-$_start,3);
时间: 2024-10-17 00:18:40