Result: Discarded
The test labeled "glob(GLOB_NOSORT)" was the faster by 0.0518 seconds, (7.124% faster)
The glob(GLOB_NOSORT) test took 0.675 seconds.
The DirectoryIterator() test took 0.7268 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 157,591 loops for a total of 3,151,820 runs.
- Line execution difference (0.000016) milliseconds.
- Avg difference (2.589) milliseconds per 157,591 loops.
- Total difference 51.77 milliseconds for 3,151,820 loops
The iteration variablity for Code 1 was (9.4286) milliseconds and Code 2 was (5.8890) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "DirectoryIterator()", was:
$result = array(); foreach (new DirectoryIterator($GLOBALS['basedir'] . '/tests') as $file) { if (!$file->isDot()) $result[] = $file->getFilename(); }
The second test, "glob(GLOB_NOSORT)", was:
$result = array(); foreach (glob($GLOBALS['basedir'] . '/tests/*', GLOB_NOSORT) as $file) { if ($file !== '.' && $file !== '..') $result[] = $file; }