php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22492 sizeof($array) in loop is very slow
Submitted: 2003-03-01 13:02 UTC Modified: 2003-03-02 12:27 UTC
From: benji at daystream dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 4.3.0 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: benji at daystream dot com
New email:
PHP Version: OS:

 

 [2003-03-01 13:02 UTC] benji at daystream dot com
This issue was opened previously and closed without resolution two and a half years ago due to lack of feedback in bug #6608. I made a comment there but I'm not sure if closed topics are seen, so I'm opening it here. I apologize if I shouldnt have opened a new bug report.

I'm running on OSX with PHP 4.3.0. The performance with a large array that uses sizeof() in a loop is very poor. It's abut 50X slower than it should be.

The following takes 8-10 seconds:
for ($i=1;$i<=sizeof($spell);$i++) {
     $sentence=str_replace($spell[$i][0],$spell[$i][1],$sentence); 
}

Whereas the following takes only .18 seconds:
$end=sizeof($spell);
for ($i=1;$i<=$end;$i++) {
     $sentence=str_replace($spell[$i][0],$spell[$i][1],$sentence); 
}

Other notes that might help: the array is stored in a file accessed by require_once(), and the loop is in a function that brings $spell in as a global variable.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-01 13:09 UTC] gschlossnagle@php.net
I haven't reopened you previous bug due to the fact that 
you dont have a replicateable testcase and my testcase 
doesn't reproduce anything close to your result.  This 
should be tracked in 6608 (which I just posted to).
 [2003-03-02 12:27 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

See bug #6608

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Feb 26 17:01:25 2020 UTC