Result: DiscardedThe test labeled "for" was the faster by 0.0435 seconds, (3.808% faster)
The for test took 1.0997 seconds.
The foreach test took 1.1432 seconds.
Each test case ran 20 random code order iterations consisting of 285,812 loops for a total of 5,716,240 runs.
- Line execution difference (0.000008) milliseconds.
- Avg difference (2.177) milliseconds per 285,812 loops.
- Total difference 43.53 milliseconds for 5,716,240 loops
The iteration variablity for Code 1 was (8.2423) milliseconds and Code 2 was (5.6565) milliseconds. The lower and the closer together there values are the more accurate the results are.
The first test, "foreach", was:
$range = range(0, 100); foreach ($range as $n) $GLOBALS['dummy'] = $n;
The second test, "for", was:
for ($n = 0; $n <= 100; $n++) $GLOBALS['dummy'] = $n;