#46039 [Opn->Asn]: ArrayObject iteration is slow
| From: | jani@php.net | Date: | Wed, 10 Sep 2008 20:18:30 +0000 |
| Subject: | #46039 [Opn->Asn]: ArrayObject iteration is slow | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-128854@lists.php.net to get a copy of this message | ||
ID: 46039
Updated by: jani@php.net
Reported By: anthony at anthonybush dot com
-Status: Open
+Status: Assigned
Bug Type: Performance problem
Operating System: Mac OS X 10.5.4
PHP Version: 5.2.6
-Assigned To:
+Assigned To: helly
New Comment:
Marcus, give your feedback to this.
Previous Comments:
------------------------------------------------------------------------
[2008-09-10 07:00:51] anthony at anthonybush dot com
Description:
------------
ArrayObject iteration is slow. I iterated over an ArrayObject (small
and large) many times. I expected iteration performance to be near
that
of a regular array. Instead, iteration on ArrayObject actually took
5.5
to 6 times longer than using a regular array. This caused my
real-world
script to go from 8 seconds execution time to 47 seconds on average.
See also "bogus" bug 38528: http://bugs.php.net/bug.php?id=38528
Reproduce code:
---------------
<?php
$data = 'We will test a simple string first.';
$numElements = 100; $numReadLoops = 50; $arr = array();
$startTime = microtime(true);
for ($i = 0; $i < $numElements; $i++) { $arr[] = $data; }
for ($i = 0; $i < $numReadLoops; $i++) { foreach ($arr as $element) {}
}
$totalArrayTime = (microtime(true) - $startTime);
echo $totalArrayTime . " seconds.\n";
unset($arr);
$arr = new ArrayObject();
$startTime = microtime(true);
for ($i = 0; $i < $numElements; $i++) { $arr[] = $data; }
for ($i = 0; $i < $numReadLoops; $i++) { foreach ($arr as $element) {}
}
$totalArrayObjectTime = (microtime(true) - $startTime);
echo $totalArrayObjectTime . " seconds.\n";
echo "ArrayObject took " . round($totalArrayObjectTime /
$totalArrayTime, 2) . " times longer.\n";
?>
Expected result:
----------------
ANY seconds.
ANY seconds.
ArrayObject took 1 times longer.
Actual result:
--------------
0.00055193901062 seconds.
0.00314903259277 seconds.
ArrayObject took 5.71 times longer.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46039&edit=1