Issue Bug Closed

#22199Use array_map() for t3lib_div::intExplode

Georg Ringer 02/26/10, 08:32 updated 07/02/10, 11:16

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
<?php

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)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.