get_class_methods性能是Reflection的2倍 (简单功能时特殊功能除外)
测试结果
测试代码
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 '
';
}