It’s hard to imagine pushing the limits of object oriented PHP so far that your web servers choke, but the truth is those limits are reached faster than you think. We’ve run some tests over at Wufoo and it turns out that any sort of mass object creation is pretty much not going to work at scale. The problem is this limit on object creation forces developers to balance code consistency, which is desirable—especially for the old-schoolers, with performance. While replacing objects with arrays when possible makes things a little better, the most performance friendly approach involves appending strings. For your convenience, we’ve run some tests that measure page execution times and memory usage to create the following guideline to help you plan out what areas of your code may have to break away from an object oriented nature.
The Benchmarks
Basically, we set up a simple PHP page to iterate over a loop and create 1) a giant concatenated string, 2) an array of arrays containing the word ‘test’, and 3) an array of objects with one variable set to ‘test’.
Load Time | Memory Used | |
Control | 12.6ms | 1.42mb |
11,000 strings | 15.7ms | 1.45mb |
11,000 arrays | 26.6ms | 3.99mb |
11,000 objects | 148.8ms | 7.70mb |
25,000 arrays | 44.1ms | 7.25mb |
1,500,000 strings | 253.2.6ms | 7.14mb |
No comments:
Post a Comment