php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46039 ArrayObject iteration is slow
Submitted: 2008-09-10 07:00 UTC Modified: 2008-11-19 14:45 UTC
From: anthony at anthonybush dot com Assigned: helly (profile)
Status: Closed Package: Performance problem
PHP Version: 5.2.6 OS: Mac OS X 10.5.4
Private report: No CVE-ID: None
 [2008-09-10 07:00 UTC] 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.






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-10 20:18 UTC] jani@php.net
Marcus, give your feedback to this.
 [2008-11-19 14:45 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC