From: carl at topthetable dot com Operating system: Redhat 7.2 PHP version: 4.3.1 PHP Bug Type: Performance problem Bug description: count() is slow when used with large arrays
count() is increasingly slow when used to count large arrays. This is using 4.3.1 (compiled from source) on a Redhat 7.2 box. The box has about 80Mb free, so it's not a paging issue. It works as expected on Mac OS X running 4.3.1-dev. Looking at PHP's and Zend's source, I would expect the time taken to return the count() of an array to be similar regardless of the size of the array. Below is a script to demonstrate the problem. <? $st = microtime(); echo "Script started: ".microtime()."\n"; dosize( 10 ); dosize( 20 ); dosize( 50 ); dosize( 100 ); dosize( 200 ); dosize( 500 ); dosize( 1000 ); dosize( 5000 ); dosize( 10000 ); function dosize( $y ) { echo "Doing size $y\n"; echo " Starting array building:".microtime()."\n"; $t = array(); for ( $i=0; $i<$y; $i++ ) { $t[] = array( array( "3", "1" ), "3", array( array ( "5", "1", "8" ) ) ); } echo " Array built: ".microtime()."\n"; count( $t ); echo " Count finished: ".microtime()."\n"; } ?> -- Edit bug report at http://bugs.php.net/?id=22435&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22435&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22435&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22435&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22435&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22435&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22435&r=support Expected behavior: http://bugs.php.net/fix.php?id=22435&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22435&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22435&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22435&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22435&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22435&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22435&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22435&r=gnused