#18829 [NEW]: array_pop, array_shift, array_push... functions very slow with large arrays
| From: | jean-charles dot rogez at devoteam dot com | Date: | Fri, 09 Aug 2002 11:22:30 +0000 |
| Subject: | #18829 [NEW]: array_pop, array_shift, array_push... functions very slow with large arrays | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-16376@lists.php.net to get a copy of this message | ||
From: jean-charles.rogez@devoteam.com
Operating system: Linux RedHat 7.1
PHP version: 4.2.2
PHP Bug Type: Arrays related
Bug description: array_pop, array_shift, array_push... functions very slow with large arrays
The following program takes a very long time to execute.
On the same machine (P4 1.5GHz), under the same conditions, with N=50, PHP
needs 87m30s !?!! The same program written in PERL 5.6 needs only 2.415s
and in python 2.1.2 3.273s ! array_pop and array_push functions seems to
be extremelly slow with large arrays. This problem has been detected on
PHP 4.0.6 and is still present in 4.2.2.
4.2.2 was compiled with the default settings (configure without
arguments).
<?php
function test_lists() {
global $size;
# create a list of integers (Li1) from 1 to SIZE
$Li1 = array();
$Li1 = array_pad($Li1, $size, 0);
# copy the list to Li2 (not by individual items)
$Li2 = $Li1;
$Li3 = array();
# remove each individual item from left side of Li2 and
# append to right side of Li3 (preserving order)
while ($Li2) {
$Li3[] = array_shift($Li2);
}
# Li2 must now be empty
# remove each individual item from right side of Li3 and
# append to right side of Li2 (reversing list)
while ($Li3) {
$Li2[] = array_pop($Li3);
}
# Li3 must now be empty
# reverse Li1 in place
$Li1 = array_reverse($Li1);
# check that first item is now SIZE
if ($Li1[0] != $SIZE) return(0);
# compare Li1 and Li2 for equality
$len1 = count($Li1);
$len2 = count($Li2);
$lists_equal = ($len1 == $len2);
if (! $lists_equal) return(0);
for ($i=0; $i<$len1; $i++) {
if ($Li1[$i] != $Li2[$i]) {
$lists_equal = 0;
break;
}
}
if (! $lists_equal) return(0);
# return the length of the list
return($len1);
}
$size = 10000;
$ITER = $argv[1];
if ($ITER < 1) $ITER = 1;
$result = 0;
?>
--
Edit bug report at http://bugs.php.net/?id=18829&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18829&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18829&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18829&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18829&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18829&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18829&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18829&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18829&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18829&r=globals