Test: (array) vs. array
Does the (array) cast work better than the array() construct?
View test history (1) Run this test again Return to test menuResult: Discarded
The test labeled "array()" was the faster by 0.0041 seconds, (0.367% faster)
The array() test took 1.1219 seconds.
The (array) test took 1.1261 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 290,867 loops for a total of 5,817,340 runs.
- Line execution difference (0.000001) milliseconds.
- Avg difference (0.207) milliseconds per 290,867 loops.
- Total difference 4.13 milliseconds for 5,817,340 loops
The iteration variablity for Code 1 was (4.6255) milliseconds and Code 2 was (3.3514) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "(array)", was:
for ($j = 0; $j < 1000; $j++) $GLOBALS['dummy'] = (array) $j;
The second test, "array()", was:
for ($j = 0; $j < 1000; $j++) $GLOBALS['dummy'] = array($j);