note 117623 added to splobjectstorage.offsetget
| From: | kontrollfreak+php at gmail dot com | Date: | Fri, 10 Jul 2015 13:47:16 +0000 |
| Subject: | note 117623 added to splobjectstorage.offsetget | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203073@lists.php.net to get a copy of this message | ||
SplObjectStorage::offsetGet() can become EXTREMELY slow depending on the associated data (PHP 5.6).
<?php
// SplObjectStorage
$object = new stdClass;
$test = new SplObjectStorage;
$test->attach($object, str_repeat("\0", 1024*1024));
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$test->offsetGet($object);
}
var_dump(microtime(true) - $start); // 76 seconds!
// Array + spl_object_hash()
$object = new stdClass;
$test = [];
$test[spl_object_hash($object)] = str_repeat("\0", 1024*1024);
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$temp = $test[spl_object_hash($object)];
}
var_dump(microtime(true) - $start); // 0.3 seconds
----
Server IP: 72.52.91.14
Probable Submitter: 46.59.155.121
----
Manual Page -- http://php.net/manual/en/splobjectstorage.offsetget.php
Edit -- https://master.php.net/note/edit/117623
Del: integrated -- https://master.php.net/note/delete/117623/integrated
Del: useless -- https://master.php.net/note/delete/117623/useless
Del: bad code -- https://master.php.net/note/delete/117623/bad+code
Del: spam -- https://master.php.net/note/delete/117623/spam
Del: non-english -- https://master.php.net/note/delete/117623/non-english
Del: in docs -- https://master.php.net/note/delete/117623/in+docs
Del: other reasons-- https://master.php.net/note/delete/117623
Reject -- https://master.php.net/note/reject/117623
Search -- https://master.php.net/manage/user-notes.php