首页 > 其他 > 详细

get_class_methods vs Reflection

时间:2014-03-25 11:17:20      阅读:470      评论:0      收藏:0      [点我收藏+]

get_class_methods vs Reflection


get_class_methods性能是Reflection2倍 (简单功能时特殊功能除外)

测试结果


bubuko.com,布布扣


测试代码

class Test {

    public function hello() {
        
    }

    public function helloa() {
        
    }

    public function hellob() {
        
    }

}

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

$test = new Test();
for ($index1 = 0; $index1 < 10; $index1++) {
    $begin1 = microtimeFloat();
    for ($index = 0; $index < 1000; $index++) {
        $class = new ReflectionClass($test);
        $methods = $class->getMethods();
        foreach ($methods as $method) {
            $method->invoke($test);
        }
    }
    echo microtimeFloat() - $begin1 . ‘----‘;

    $begin2 = microtimeFloat();
    for ($index = 0; $index < 1000; $index++) {
        $methods = get_class_methods($test);
        foreach ($methods as $method) {
            $test->$method();
        }
    }
    echo microtimeFloat() - $begin2;
    echo ‘<br/>‘;
}


get_class_methods vs Reflection,布布扣,bubuko.com

get_class_methods vs Reflection

原文:http://blog.csdn.net/starparker/article/details/21974837

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!