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

php使用魔法函数和不使用魔法函数比较

时间:2015-07-30 00:28:28      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

/**
* use magic 0.31868386268616s
* not use magic 0.11876797676086s
*/
class Test {
    private $varstr = "123";

    function __get($name) {
        return $this->varstr;
    }
}

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();

$i = 0;
while ($i<100000) {
    $i++;
    $t = new Test();
    $t->varstr;
}

$time_end = microtime_float();
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";

建议尽量少用PHP魔法函数

php使用魔法函数和不使用魔法函数比较

标签:

原文地址:http://www.cnblogs.com/gide/p/4687744.html

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