码迷,mamicode.com
首页 > Web开发 > 详细

4-1 减少PHP魔法函数的使用 __get($name)返回私有变量 取执行时间

时间:2017-03-07 08:44:59      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:art   mat   new   pen   contract   使用   images   current   span   

魔法函数执行时间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);
View Code

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);
View Code

 

4-1 减少PHP魔法函数的使用 __get($name)返回私有变量 取执行时间

标签:art   mat   new   pen   contract   使用   images   current   span   

原文地址:http://www.cnblogs.com/jiaochengli/p/6512786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!