Skip to content

Instantly share code, notes, and snippets.

@caefer
Created November 25, 2010 09:10
Show Gist options
  • Save caefer/715114 to your computer and use it in GitHub Desktop.
Save caefer/715114 to your computer and use it in GitHub Desktop.
benchmarks RecursiveDirectoryIterator against glob()
<?php
$testDir = dirname(__FILE__).'/test/';
$startTime = microtime(true);
$touches = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testDir)) as $filepath)
{
touch($filepath);
$touches++;
}
printf("Touched %d files in %.4f seconds with iterators".PHP_EOL, $touches, microtime(true) - $startTime);
$startTime = microtime(true);
$touches = 0;
for($i=0; $i<5; $i++)
{
foreach(glob($testDir.'*.*') as $filepath)
{
touch($filepath);
$touches++;
}
$testDir .= '*/';
}
printf("Touched %d files in %.4f seconds with glob".PHP_EOL, $touches, microtime(true) - $startTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment