ID:               18829
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Assigned
+Status:           Won\'t fix
 Bug Type:         Arrays related
 Operating System: Linux RedHat 7.1
 PHP Version:      4.2.2
 Assigned To:      rodif_bl
 New Comment:

PHP is not perl, since arrays are bastards (the unwed child of a hash
and array) there is really not a more efficient way to handle this,
without breaking things badly...


Previous Comments:
------------------------------------------------------------------------

[2002-08-13 20:45:48] [EMAIL PROTECTED]

Assigning to Brad, as he seems to be working on it... a bit.

------------------------------------------------------------------------

[2002-08-13 04:11:32] [EMAIL PROTECTED]

In perl :

@a = (1, 2, 3);
shift(@a);
print "$a[0], $a[1]";

Result : 2, 3

This is correct.

I don't know how the shift function is implemented in perl, but i think
arrays are not reindexed like in PHP, else it shouldn't be so fast.

------------------------------------------------------------------------

[2002-08-12 09:18:55] [EMAIL PROTECTED]

The problem wasn't just array_shift it was array_shift and array_pop.
array_shift is whats causing the slowness now but way its implemented
now I really don't think it can get much faster. Basically when you
shift of the top of the array it needs to re-index the entire array
meaning if you have 10,000 records it needs to loop thru all 10,000
changing the index. If the function didn't need to do this it wouldn't
take nearly as long. Does it work this way in perl or python.

$a = array(1,2);
array_shift($a);
echo $a[0];

------------------------------------------------------------------------

[2002-08-12 04:25:03] [EMAIL PROTECTED]

Same results than you. The script takes approximately 4 minutes on my
P4 1.5Ghz with the latest CVS (before it was 87m...). After correction
of the array_shift function, PHP should be in the same time than Perl
or Python.

------------------------------------------------------------------------

[2002-08-10 05:39:19] [EMAIL PROTECTED]

I did some testing on your function and it seems that array_shift is to
blame. If I avoid using that function, the execution time drop down to
few seconds. To cut down the problem:

  $size = 5000;
  $Li1 = array();
  $Li1 = array_pad($Li1, $size, 0);
  $Li2 = array();

  while ($Li1) {
    $Li2[] = array_shift($Li1);
  }

This takes 1.8 s on my P3 933 MHz. If I increase $size to 10000 it
takes 16 s.

The rest of array functions seem to be working fine.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/18829

-- 
Edit this bug report at http://bugs.php.net/?id=18829&edit=1

Reply via email to