Results 1 to 4 of 4
Thread: include/require performance
May 4, 2012, 06:10 #1
- Join Date
- Oct 2005
- Milton Keynes, UK
- 9 Post(s)
- 2 Thread(s)
Profiling my scripts, the biggest drain on performance is the autoloader, specifically the require/include line.
A current site includes 38 files.
I did a quick test using include/require/require once/include once. Profiling just the autoload function and changing only the include/require line here's what I got just as a very basic test.
require_once 124.75ms require 116.64ms include_once 120.56ms include 119.24ms
All very close. Nothing really in it. However, 38 calls to include/require are using 70% of my script's CPU time so it's a hefty chunk of resources and easily the most resource intensive function I have.
Now that still seemed a lot to me but perhaps it just a file I/O bottleneck. As a basic test, I tried:
eval('?>' . file_get_contents($file));
The result... 24.29ms roughly five times faster. This is rather astonishing. obviously eval is bad™ but this proves that include/require are doing a hell of a lot more than simply loading the file. By using eval(file_get_contents()) I've improved my entire script performance by almost 100%.
Any idea why include should be so comparatively slow?
edit: the files being included are doing no real processing on include, they are all just class definitions.