<?php
$iter = 10000;
$array = range(0, $iter);
$function = function($val, $key) {};
$t = microtime(true);
for($i = 0; $i < $iter; $i++)
{
foreach($array as $key => $val)
{
$function($val, $key);
}
}
echo 'foreach: '.(microtime(true) - $t).'\n';
$t = microtime(true);
for($i = 0; $i < $iter; $i++)
{
array_walk($array, $function);
}
echo 'array_walk: '.(microtime(true) - $t).'\n';
$t = microtime(true);
for($i = 0; $i < $iter; $i++)
{
array_map($function, $array, array_keys($array));
}
echo 'array_map: '.(microtime(true) - $t).'\n';
- Output for 5.3.5 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7
Process exited with code 137.
preferences:
95.88 ms | 402 KiB | 117 Q