ID:              30295
 User updated by: oliver at burtchen dot com
 Reported By:     oliver at burtchen dot com
 Status:          Open
 Bug Type:        Performance problem
 PHP Version:     5.0.2
 New Comment:

Using array_key_exists($i, &$a) is my solution for now, too. It works
okay. Happy debugging...  ;-)


Previous Comments:
------------------------------------------------------------------------

[2004-10-01 01:17:04] [EMAIL PROTECTED]

for a short term solution use 
array_key_exists($i, &$a);

------------------------------------------------------------------------

[2004-09-30 23:23:28] oliver at burtchen dot com

Description:
------------
it looks loke array_key_exists() makes a copy of the given array if
there is a reference to that array. if there is no reference,
everything works well.

Reproduce code:
---------------
// just to get the time in microseconds
function getmicrotime() {
   list($usec, $sec) = explode(" ",microtime());
   return ((float)$usec + (float)$sec);
}


$cnt = 2000;
$a = array_fill(0, $cnt, 'foo');


// this works as aspected very fast

$mtime = getmicrotime();

for ($i = 0; $cnt > $i; $i++)
        array_key_exists($i, $a);

echo getmicrotime() - $mtime . '<br>';


$b =& $a;  // making a reference, but not using it


// this will take a huge amount of time, but it's the same code as
above

$mtime = getmicrotime();

for ($i = 0; $cnt > $i; $i++)
        array_key_exists($i, $a);

echo getmicrotime() - $mtime . '<br>';



Expected result:
----------------
the two loops should work the same.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30295&edit=1

Reply via email to