|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-01-12 13:48 UTC] akorthaus at web dot de
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
count: 2034 251.505897045 count: 2034 155.706785917 Only difference: foreach(range(1, 5000) as $unused) $files = scandir('C:\WINDOWS\System32'); So, not on Win32. Do a foreach like I have done and spread the function call over quite a few calls, because with repeated execution of a single function call, it went back and forth for me.I tried php5-STABLE-200501140930 with the same result The size of the directory-listing ("files"): number of files: ls -1 files | wc -l 10000 Number of bytes: ls -1 files | wc -c 330000