我做了一些测试。 (感谢Aufziehvogel的施工)
$count = 100000;
$dir = dirname(__FILE__);
$startScan = microtime(true);
for ($i=0;$i
$array = scandir($dir);
}
$endScan = microtime(true);
$startRead = microtime(true);
for ($i=0;$i
$handle = opendir($dir);
while (false !== ($entry = readdir($handle))) {
// We do not know what to do
}
}
$endRead = microtime(true);
$startGlob = microtime(true);
for ($i=0;$i
$array3 = glob('*');
}
$endGlob = microtime(true);
echo "scandir: " . ($endScan-$startScan) . "\n";
echo "readdir: " . ($endRead-$startRead) . "\n";
echo "glob : " . ($endGlob-$startGlob) . "\n";
Linux服务器结果:
scandir: 0.82553291320801
readdir: 0.91677618026733
glob : 0.76309990882874
这个Reasults来自4核(8个线程)intel E3-1240 Cpu linux + Apache服务器。
但Windows服务器的结果则相反。 Windows + Apache服务器 - 英特尔Q8400 4核(4线程)
Windows Server结果:
$count = 10000; // it was on linux 100000 :)
scandir: 0.61557507515
readdir: 0.614650011063
glob : 1.92112612724
(文件夹包含13个文件。如果文件增加,结果可能不同)