note 95958 deleted from class.splobjectstorage by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Feb 2010 17:32:13 +0000 |
| Subject: | note 95958 deleted from class.splobjectstorage by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165631@lists.php.net to get a copy of this message | ||
Note Submitter: David@OnDevice
----
I should have qualified with some test results- so I made some comparisons- and was shocked. But
first, the caveats- I'm not going to spam this entry with my PHP implementation, so there is a
certain amount of trust involved on your behalf that its a lean efficient implementation. Second,
that the test itself was well produced.
Taking an array of 5000 unique integers (generated before benchmark timing), I tested
SplObjectStorage and my php HashMap by iterating through the 5000 unique integers and:
i. Adding a scalar key and value to the target collection
ii. Testing for the key in the collection
iii. Getting the value for the scalar key
iv Removing the key
With error_reporting set to E_ERROR (suppressing warnings from SplObjectCollection), the results
were:
HashMap average: 0.0030831205844879 seconds
SplObjectCollection average: 6.0224056243896E-6
Thats pretty impressive on part of SplObjectCollection! The only time that my hashmap outperformed
spl was with error_reporting set to E_ALL- as would be expected because I have implemented an error
handler.
Using @ and SplObjectCollection using ArrayAccess notation does nothing to suppress the warnings
however- that is,
<?php
$spl= new SplObjectStorage;
@$spl[0]= ''; // warnings still triggered
?>
Will SplObjectCollection suppress warnings about scalar keys in the future? I hope so....