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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mladdens at eunet dot yu
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 17:01:58 2024 UTC