Matthew Turland is presenting. If you haven’t heard of him, you’re a nub (k, not really but I really wanted to put that in a post somewhere). He’s an auther for php|architect and author of Web Scrapign with PHP, a contributer to Zend Framework, lead developer of Phergie. So yeah, kind of a big deal. He currently works at Synacor which provides internet solutions to ISPs, media companies and advertisers.
We’ll be looking at a lot of benchmarks. The code is available on github so you can compare the performance results for yourself.
Starting simple with a list. The corresponding structure for this is SplFixedArray. It is like an array but with fixed length. Only allows integers >= 0 for keys. As you have more elements, SPL overtakes arrays in being better for memory usage.
Same unlimited size as arrays without the associated hash map algorithm. There is less performance but better memory usage.
Two very basic operations: push and pop. LIFO (Last In, First Out) data structure. The class doesn’t get better performance. There seems to be such an odd bottleneck. He’ll get to filing a bug later. ;p
Two operation: enqueue and dequeue. FIFO (First In, First Out) data structure. Again a correlation of element size to performance improvement.
Heaps operate based off of a comparison function. It internally reorders items based on the comparrison. Worst case is you can override SplHeap::compare(). Sorting happens as you insert the items. Again, smaller number of elements, you should stick with arrays but if you’re dealing with a large number of elements, you will see a performance difference.
Priority queues are very similar to triage. Similar to a heap, in fact it uses a heap internally for storage. Accepts a priority with the element value. Also compare can be overridden.
Similarity between doing queries with joins. Slide shows some crayons, wonder what the analogy is or maybe he likes crayons. I like crayons. Queries with UNION operation is a set operation. Hash table with objects for keys is the best visual for understanding composite hash map. Set focuses on a group of values rather than individual values with operations like union, intersection, difference, etc. Using SplObjectStorage for the code examples.
Etienne Kneuss did a lot of the work on the new SPL features in PHP 5.3 so we can thank him for the new hotness. Etienne’s blog is a good resource for SPL as well as the SPL entries in the PHP manual. Elizabeth Smith has written up a post called “SPL to the Rescue” which is useful. Elazar will also put this presentation as a blog post on his site.
Future of SPL
- contains nodes and edges connecting them
- edge costs
- Acyclic unidirection graph
- hierarchical in nature
Elazar did a great job of taking concepts that would normally go over my head and making them understandable.
Looking for something?
Use the form below to search the site:
Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!