From: akorthaus at web dot de
Operating system: Linux 2.4.28 (Gentoo)
PHP version: 5.0.3
PHP Bug Type: Performance problem
Bug description: scandir() is slower than user-function
Description:
------------
I do not understand why the new scandir() function is slower than an own
PHP-function which does the same (I used the "Example 2. PHP 4
alternatives to scandir()" from manual).
I tried this with 50 - 100.000 files, but the result is allways the same.
my_scandir() is about 50%-100% faster. If I don't sort, it is about 400%
faster.
Reproduce code:
---------------
<?php
function my_scandir($dir) {
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
return $files;
}
$t1= microtime(TRUE);
$files = my_scandir('/tmp');
$t2= microtime(TRUE);
echo "count: ".count($files)."\n";
echo $t2-$t1;
echo "\n";
?>
<?php
$t1 = microtime(TRUE);
$files = scandir('/tmp');
$t2= microtime(TRUE);
echo "count: ".count($files)."\n";
echo $t2-$t1;
echo "\n";
?>
Expected result:
----------------
I expect the c-function to be faster
Actual result:
--------------
the php-function is about 50-100% faster
--
Edit bug report at http://bugs.php.net/?id=31515&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31515&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31515&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31515&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31515&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31515&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31515&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31515&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31515&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31515&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31515&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31515&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31515&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31515&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31515&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31515&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31515&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31515&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31515&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31515&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31515&r=mysqlcfg