autoloadのほうがrequire_onceよりも早い?

ウノウラボの記事で知ったのですが、

requireはrequire_once()より3-4倍遅い?
空ファイルを forループで1万回呼んだ結果、4倍程度早かった。

元ネタでは

Ilia advises against using magic functions like __autoload() and __get(), but the advantage of __autoload() in particular is obvious in any large project and is used by many php frameworks. My primitive testing, however, shows inverse results. With a simply autoload requiring a class and 10000 loops of new Foo() versus require_once(‘foo.php’); new Foo() shows that __autoload() is ~3.7 times faster.

こう書かれています。うーむ。require_onceで読み込んでからnewしたほうが早いに違いないと思っていましたが、__autoloadなら内部処理で全て賄えるのを、require_onceをスクリプトで実行する分、オーバーヘッドができてしまうということなのでしょうか。これからは__autoloadを気兼ねなく使えそうです。

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">