#22492 [NEW]: sizeof($array) in loop is very slow

From: Date: Sat, 01 Mar 2003 19:02:12 +0000
Subject: #22492 [NEW]: sizeof($array) in loop is very slow
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-34587@lists.php.net to get a copy of this message
From: benji at daystream dot com Operating system: OSX PHP version: 4.3.0 PHP Bug Type: Performance problem Bug description: sizeof($array) in loop is very slow This issue was opened previously and closed without resolution two and a half years ago due to lack of feedback in bug #6608. I made a comment there but I'm not sure if closed topics are seen, so I'm opening it here. I apologize if I shouldnt have opened a new bug report. I'm running on OSX with PHP 4.3.0. The performance with a large array that uses sizeof() in a loop is very poor. It's abut 50X slower than it should be. The following takes 8-10 seconds: for ($i=1;$i<=sizeof($spell);$i++) { $sentence=str_replace($spell[$i][0],$spell[$i][1],$sentence); } Whereas the following takes only .18 seconds: $end=sizeof($spell); for ($i=1;$i<=$end;$i++) { $sentence=str_replace($spell[$i][0],$spell[$i][1],$sentence); } Other notes that might help: the array is stored in a file accessed by require_once(), and the loop is in a function that brings $spell in as a global variable. -- Edit bug report at http://bugs.php.net/?id=22492&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22492&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22492&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22492&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22492&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22492&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22492&r=support Expected behavior: http://bugs.php.net/fix.php?id=22492&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22492&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22492&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22492&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22492&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22492&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22492&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22492&r=gnused

« previous php.bugs (#34587) next »