RE: [PHP] Why is the php loop, 'for()', so slow????
| From: | Chris W. Parker | Date: | Thu, 20 Nov 2003 00:12:35 +0000 |
| Subject: | RE: [PHP] Why is the php loop, 'for()', so slow???? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170359@lists.php.net to get a copy of this message | ||
Scott Fletcher <mailto:scott@abcoa.com>
on Wednesday, November 19, 2003 1:12 PM said:
> function CBC_XML_BreakUp(&$strResponse_XML, &$strResponse_HTML)
>
> {
[snip]
Wow I didn't think you were going to post your whole program. :0
1. Are you sure the for() loop is the slow part?
2. As someone already suggested, calculating the sizeof() outside of the
loop should help a lot. Another enhancement is changing your for() to
while(). (This is a small enhancement but makes a bigger difference as
your iterations increase.)
REGULAR for() loop construct:
$iMax = 99;
for($iCnt = 0; $iCnt < $iMax; $iCnt++)
{
}
OPTIMIZED:
$iMax = 99;
$iCnt = -1;
while(++$iCnt < $iMax)
{
}
Like I said it's only slightly faster, but might make a difference
depending on your number of iterations.
3. I think what may be slowing you down is your substr() calls. Maybe
there is a substitute function that is faster? (I don't have any ideas
unfortunately.)
Let us know if you figure something out.
HTH,
Chris.
--
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/