PHP Benchmarks

Performance comparison of PHP code alternatives.

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 menu

Historical Results

Based on (1) saved test runs, The test labeled "array_map()" was (on average) the faster by 0.004 seconds, (0.743% faster)

array_map() 100%
array_walk() 99.257%

The array_map() test took 0.5317 seconds.
The array_walk() test took 0.5357 seconds.


Each test case ran 20 random code order iterations consisting of 148,247 loops for a total of 2,964,940 runs.

  • Line execution difference (0.000001) milliseconds.
  • Avg difference (0.000) milliseconds per 148,247 loops.
  • Total difference 3.98 milliseconds for 2,964,940 loops

The iteration variablity for Code 1 was (0.0000) milliseconds and Code 2 was (0.0000) milliseconds. The lower and the closer together there values are the more accurate the results are.


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');

Running: Linux (x86_64:1 GB) PHP (