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

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: array_map() vs. foreach

Is there a benefit to using array_map() over a simple foreach?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "array_map()", was:

/*
function foo($v)
{
	return $v * 2;
}
*/

$array = array_map('foo', $GLOBALS['dummy']);

The second test, "foreach", was:

$array = array();
foreach ($GLOBALS['dummy'] as $k => $v)
	$array[$k] = $v * 2;

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