- microtime: documentation ( source)
- array_fill: documentation ( source)
- array_walk: documentation ( source)
<?php
$testBase = array_fill(0, 100000, 'testdata');
echo "Test array count: " . count($testBase) . PHP_EOL;
for($x = 0; $x < 10; $x++ ) {
echo "Test #$x" . PHP_EOL;
/* foreach test */
$testCopy = array();
$before = microtime(true);
foreach ($testBase as $key => $value) {
$testCopy[$key] = $value . 'asdasd';
}
$after = microtime(true);
$dif = $after - $before;
echo "foreach test ($before, $after): $dif" . PHP_EOL;
/* array_walk test */
$testCopy = $testBase;
$before2 = microtime(true);
array_walk($testCopy, function(&$value, $key) {
$value = $value . 'qweqwe';
});
$after2 = microtime(true);
$dif2 = $after2 - $before2;
echo "array_walk test ($before2, $after2): $dif2" . PHP_EOL;
}