It’s often discussed among PHP developers whether it’s better to include one file or many. After running performance tests I’m able to clarify that it’s sixty percent faster to include a single file of larger size over including multiple files of smaller sizes, this will be the case ~99% of the time. However if you only need one function from that file and are concerned with performance you will want to identify and extrude that function.
| File Size | Start | End | Elapsed | Ratio | |
|---|---|---|---|---|---|
| 1 File | 8013 | 0.32117600 1296792534 | 0.32184200 1296792534 | 0.000666 | 0.484363636364 |
| 4 Files | 2003 | 0.31978200 1296792534 | 0.32115700 1296792534 | 0.001375 | 2.06456456456 |
1 file (8kb) loads faster than loading 4 smaller files (2kb each)
For this test were you using an opcode cache?
An opcode cache was not used for these tests.
I’d be interested to see if the opcode speeds up the includes or not on the following runs. I’ve never really had a change to test opcode caches in depth to see which parts of PHP they really help out.
I imagine it would help quite substantially in the case of includes. From my understanding of opcode caching, it would cache a file including multiple files as a single file with the includes, after all the goal of opcode caching is to cache on the compiler level. We’ll be implementing opcode caching in a project I’m working on at a later date, I’ll see what benchmarks I can run and report those results.