I’ve always heard the include_once() and require_once() functions were computationally expensive in PHP, but I never knew how much. I tested the following out on my i7 2010 MacBook Pro using PHP 5.3.4 as shipped by Apple.
This first test uses include_once() to keep track of how often a file is included:
Took: 10.020140171051 sec
This second example uses include() and uses in_array() to keep track of if I loaded the include:
Took: 0.27652382850647 sec
For both, the include had the following computation:
Lesson learned: Avoid using _once if you can avoid it.
Update: That means something like this will theoretically be faster:
When people talk about open source they often talk about the products, not the process. That’s not really a bad thing (it is after all about the product), but it overlooks some really interesting things sometimes. For example open source tools used in open development.
Another test that many are familiar with is Acid 2 which essentially is checking CSS support among browsers. Ironically this one too was released when Gecko is somewhat late in the development cycle.
Efforts like this really help web development by allowing browser developers to have a baseline to compare their strengths and weaknesses. Having a little healthy competition as motivation can be pretty helpful too .
About Robert Accettura
Robert Accettura is a web developer, Mozilla contributor, open source advocate, tech enthusiast and occasional trouble maker. more »
You can follow this blog via RSS or follow me on any of the social sites below.