Skip to content

Instantly share code, notes, and snippets.

@Majkl578
Created March 23, 2011 16:53
Show Gist options
  • Save Majkl578/883457 to your computer and use it in GitHub Desktop.
Save Majkl578/883457 to your computer and use it in GitHub Desktop.
<?php
$dir = '/tmp/speedtest'; #10k of files, ext4 FS
$steps = 20;
$times = array(0,0,0,0);
for ($round = 0; $round < $steps; $round++) {
clearstatcache();
$as = microtime(TRUE);
$ite = new DirectoryIterator($dir);
for ($ite->rewind(); $ite->valid(); $ite->next()) {
$f = $ite->current();
}
$times[0] += microtime(TRUE) - $as;
unset($ite, $f);
clearstatcache();
$bs = microtime(TRUE);
for ($p = opendir($dir); ($f = readdir($p)) !== FALSE; ) {
}
closedir($p);
$times[1] += microtime(TRUE) - $bs;
unset($p, $f);
clearstatcache();
$cs = microtime(TRUE);
$d = scandir($dir);
for ($i = 0, $s = count($d); $i < $s; $i++) {
$f = $d[$i];
}
$times[2] += microtime(TRUE) - $cs;
unset($d, $i, $s, $f);
clearstatcache();
$ds = microtime(TRUE);
$d = glob("$dir/*");
for ($i = 0, $s = count($d); $i < $s; $i++) {
$f = $d[$i];
}
$times[3] += microtime(TRUE) - $ds;
unset($d, $i, $f, $s);
}
echo implode(', ', array_map(function ($t) use ($steps) { return $t / $steps; }, $times));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment