標籤:art mat new pen contract 使用 images current span
魔法函數執行時間0.635
<?phpclass 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);View Code
public直接擷取執行時間為
<?phpclass 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);View Code
4-1 減少PHP魔法函數的使用 __get($name)返回私人變數 取執行時間