Test: foreach (fcall) vs. foreach ($temp)
Is the array being iterated cached? It could cause some nasty side effects to OOP if it is, but maybe PHP is smart about this.
View test history (2) Run this test again Return to test menuResult: Saved
The test labeled "foreach (fcall)" was the faster by 0.0053 seconds, (1.306% faster)
The foreach (fcall) test took 0.403 seconds.
The foreach ($temp) test took 0.4083 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 113,913 loops for a total of 2,278,260 runs.
- Line execution difference (0.000002) milliseconds.
- Avg difference (0.267) milliseconds per 113,913 loops.
- Total difference 5.33 milliseconds for 2,278,260 loops
The iteration variablity for Code 1 was (0.6886) milliseconds and Code 2 was (0.6655) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "foreach (fcall)", was:
foreach (array_merge(range(1, 10), range(11, 20), range(21, 30), range(31, 40)) as $v) $GLOBALS['dummy2'] = $v;
The second test, "foreach ($temp)", was:
$temp = array_merge(range(1, 10), range(11, 20), range(21, 30), range(31, 40)); foreach ($temp as $v) $GLOBALS['dummy2'] = $v;