note 90371 added to class.arrayobject
| From: | skrebbel at gmail dot com | Date: | Sat, 18 Apr 2009 10:25:50 +0000 |
| Subject: | note 90371 added to class.arrayobject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153464@lists.php.net to get a copy of this message | ||
According to my benchmarks, doing foreach() on an ArrayObject is significantly slower than doing so
on a vanilla array(). However, inserting keys and retrieving them is almost the same speed.
So, if performance is important, consider not using ArrayObject or descendant classes when
you're iterating over its values a lot.
These are my timing results, using PEAR::Benchmark:
ArrayObject fill 0.01441502571106
ArrayObject read_key 0.018320083618164
ArrayObject read_foreach 2.1559031009674
array() fill 0.012364864349365
array() read_key 0.013092041015625
array() read_foreach 0.011217832565308
In all cases, 'fill()' inserts 10000 numbers at string keys, 'read_key()' reads
all of those values by referencing the keys, and 'read_foreach()' does the same by walking
through the array(object) with foreach().
As you can see, filling or reading from an ArrayObject by key is only 10% to 15% slower, but doing a
foreach() is 200 times as costly. I am not sure what the cause of this may be.
----
Server IP: 83.137.20.135
Probable Submitter: 87.209.185.236
----
Manual Page -- http://www.php.net/manual/en/class.arrayobject.php
Edit -- https://master.php.net/note/edit/90371
Del: integrated -- https://master.php.net/note/delete/90371/integrated
Del: useless -- https://master.php.net/note/delete/90371/useless
Del: bad code -- https://master.php.net/note/delete/90371/bad+code
Del: spam -- https://master.php.net/note/delete/90371/spam
Del: non-english -- https://master.php.net/note/delete/90371/non-english
Del: in docs -- https://master.php.net/note/delete/90371/in+docs
Del: other reasons-- https://master.php.net/note/delete/90371
Reject -- https://master.php.net/note/reject/90371
Search -- https://master.php.net/manage/user-notes.php