PHP 5 Reflection API performance

前端 未结 10 1015
不知归路
不知归路 2020-12-02 20:11

I\'m currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instancia

10条回答
  •  囚心锁ツ
    2020-12-02 20:19

    Calling a static function 1 million times will cost ~ 0.31 seconds on my machine. When using a ReflectionMethod, it costs ~ 1.82 seconds. That means it is ~ 500% more expensive to use the Reflection API.

    This is the code I used by the way:

    invokeArgs(null, array('f'));
    }
    
    echo ($b=microtime(true) - $s)."\n";
    
    echo 100/$a*$b;
    

    Obviously, the actual impact depends on the number of calls you expect to do

提交回复
热议问题