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: