Bug #22199
closedUse array_map() for t3lib_div::intExplode
0%
Description
t3lib_div::intExplode can be a lot faster by using array_map instead of a foreach and using a reference.
a small demo to test
function oldTest($arr) {
foreach ($arr as &$val) {
$val = intval($val);
}
reset($arr);
return $arr;
}
function newTest($arr) {
$arr = array_map('intval', $arr);
return $arr;
}
$testline = '0,asbs,12a,-12,NULL,12912912,129129,654,5613,abc,-1212,-8c,919';
$testArr = explode(',', $testline);
$interation = 5000;
#$interation = 1;
$timeStart = microtime();
for ($i = 1; $i <= $interation; $i++) {
$out = newTest($testArr);
#print_r($out);
}
$timeEnd = microtime();
$time = $timeEnd - $timeStart;
echo $time . ' seconds -> ' . $interation . 'x NEW
';
$timeStart = microtime();
for ($i = 1; $i <= $interation; $i++) {
$out = oldTest($testArr);
#print_r($out);
}
$timeEnd = microtime();
$time = $timeEnd - $timeStart;
echo $time . ' seconds -> ' . $interation . 'x OLD
';
?>
(issue imported from #M13675)