php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13317 Optimizing Bug for 'sizeof' function
Submitted: 2001-09-15 10:56 UTC Modified: 2001-09-15 16:05 UTC
From: mladdens at eunet dot yu Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 4.0.6 OS: Unix/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 + 45 = ?
Subscribe to this entry?

 
 [2001-09-15 10:56 UTC] mladdens at eunet dot yu
There is a huge diference in speed with these two approaches:

$file=file("file.txt");

1.
 for($i=0;$i<sizeof($file);$i++)
   ...

2.
$file_size=sizeof($file);
 for($i=0;$i<$file_size;$i++)
    ...

The second approach is much more faster, because the first seems to calculate the 'sizeof' in every iteration.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-15 16:05 UTC] joey@php.net
But that is what you have ASKED it to do.
This is the way that for() should behave. Not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC