PHP SPLObjectStorage v. Arrays: Redux

Jan 4 2013

A few years ago, I tested SPLObjectStorage and Arrays to see which performed better. My conclusion at the time was that SPLObjectStorage is the better performer.

One thing I did not examine there was the implications of size. I ran tests with a fixed size of 10,000 elements. The test was also run on PHP 5.2.

A recent email from Frederik Krautwald caused me to re-evaluate these benchmarks. Using PHP 5.4.10 on Windows 7, Frederik generated this set of benchmarks: <!--break--> DOMDocuments | 100 | 1,000 | 10,000 | 100,000 | 250,000 ------------- | ----- | ------- | -------- | --------- | -------- SPLObjectStorage ||||| Time to fill |0.0001449585|0.0014350414|0.0204849243|0.4333310127|1.9327380657 Time to Check |0.0001280308|0.0012438297|0.0177009106|0.6071338654|3.3099889755 Memory |11,080|108,288|2,196,888|21,573,296|53,146,416 Array ||||| Time to fill |0.0001769066|0.0017120838|0.0188210011|0.191464901|0.478826046 Time to Check |0.0001690388|0.0017168522|0.0188360214|0.1887331009|0.4800989628 Memory |8,704|84,272|865,704|8,524,480|21,048,760

Testing Environment

Model: HP Pavilion dv6t-6b00 CTO Quad Edition Entertainment Notebook PC Intel® CoreTM Processor: i7-2670QM CPU @ 2.20GHz System Memory: 8GB SODIMM Hynix 1333MHz OS: Windows 7 64-bit Operating System PHP Version: v5.4.10


As you can see from Frederik's tests, SPLObjectStorage seems to have a sweetspot of about 10,000, after which performance degrades.

In my own tests, I am seeing access time (Time to Check) on SPLObjectStorage stay lower than what Frederik is reporting (and lower than arrays), but I haven't yet managed to build a conclusive dataset.

Let's Do More Benchmarking

Frederik reminded me of the importance of good benchmarking. So I decided to create a GitHub repo to store PHP micro-benchmarks, starting with this one. If you'd like to contribute some simple benchmarking scripts, feel free to fork and issue pull requests.

The Benchmarks-PHP project on GitHub is where I will post these benchmarks as I go.