Project

General

Profile

Actions

Bug #22199

closed

Use array_map() for t3lib_div::intExplode

Added by Georg Ringer over 14 years ago. Updated over 14 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2010-02-26
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.3
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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)

Actions

Also available in: Atom PDF