Test: glob(no_sort) vs DirectoryIterator
No Description
View test history (2) Run this test again Return to test menuResult: Discarded
The test labeled "DirectoryIterator()" was the faster by 0.1432 seconds, (12.638% faster)
The DirectoryIterator() test took 0.9898 seconds.
The glob(GLOB_NOSORT) test took 1.133 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 249,958 loops for a total of 4,999,160 runs.
- Line execution difference (0.000029) milliseconds.
- Avg difference (7.160) milliseconds per 249,958 loops.
- Total difference 143.19 milliseconds for 4,999,160 loops
The iteration variablity for Code 1 was (4.0529) milliseconds and Code 2 was (10.0146) 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; }