Test: array_map vs. array_walk
array_walk() can change an array in place. Is this faster than creating a separate one with array_map()?
Run this test again Return to test menuResult: Discarded
The test labeled "array_map()" was the faster by 0.0505 seconds, (4.189% faster)
The array_map() test took 1.1549 seconds.
The array_walk() test took 1.2054 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 290,313 loops for a total of 5,806,260 runs.
- Line execution difference (0.000009) milliseconds.
- Avg difference (2.525) milliseconds per 290,313 loops.
- Total difference 50.50 milliseconds for 5,806,260 loops
The iteration variablity for Code 1 was (8.9388) milliseconds and Code 2 was (10.9000) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "array_map()", was:
/* function foo_map($v) { return $v + 1; } */ $GLOBALS['dummy'] = array_map('foo_map', $GLOBALS['dummy']);
The second test, "array_walk()", was:
/* function foo_walk(&$v) { $v = $v + 1; } */ array_walk($GLOBALS['dummy'], 'foo_walk');