Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: array_map vs. array_walk

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 Again Test Menu

Result

Unfortunately, no history for this test is available.

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

Running: Linux (x86_64:1 GB) PHP (7.2.22-1+ubuntu16.04.1+deb.sury.org+1)