From: anthony at anthonybush dot com Operating system: Mac OS X 10.5.4 PHP version: 5.2.6 PHP Bug Type: Performance problem Bug description: ArrayObject iteration is slow
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 bug report at http://bugs.php.net/?id=46039&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46039&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46039&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46039&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46039&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46039&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46039&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46039&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46039&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46039&r=support Expected behavior: http://bugs.php.net/fix.php?id=46039&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46039&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46039&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46039&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46039&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46039&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46039&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46039&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46039&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46039&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46039&r=mysqlcfg