Re: Performance: While or For loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2007-03-24 at 01:54 +0100, Tijnema ! wrote:
> On 3/24/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
> > On Thu, March 22, 2007 5:14 pm, Tijnema ! wrote:
> > > On 3/22/07, Jon Anderson <janderson@xxxxxxxxxxxxxxxxxx> wrote:
> > >> Your test isn't exactly fair. The for loop has no statements in it,
> > >> and
> > >> the while loop has one. Your tests show while as approx 7% faster,
> > >> while
> > >> a modified test shows an approximate 30% speed improvement:
> > >>
> > >> Do this:
> > >>
> > >> for ($i=0;$i<10000000;$i++) {}
> > >>
> > >> v.s.:
> > >>
> > >> $i = 0;
> > >> while ($i++ < 10000000) {}
> > >>
> > >> The above while loop is 30% faster than the for. A little teaking on
> > >> the
> > >> for loop, it's faster still:
> >
> > Folks:
> >
> > How often do you use a loop of any kind in PHP with enough iterations
> > that this is even significant?
> >
> > Write the code that makes sense.
> >
> > Optimize the biggest bottleneck until performance is acceptable.

It's not optimization if you just happen to write optimal code out of
habit. It's already done.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux