You are here: Re: Which is faster? While vs For, if vs if...else « PHP Programming Language « IT news, forums, messages
Re: Which is faster? While vs For, if vs if...else

Posted by Thomas Mlynarczyk on 10/18/06 18:45

Also sprach Sonnich:

> So, which is faster:
>
> for($j = 0;$j<count($array);$j++)
> or
>
> $j = 0
> while($j<count($array))
> $j++;

I don't think they make much difference. If the "direction" doesn't matter,
the following is much (!) faster as count($array) is calculated only once
and there's one expression less to evaluate:

for ( $i = count( $array ); $i--; )
{
// do useful stuff
}

OTOH, if the "useful stuff" takes a lot of time, the performance gain might
turn out to be negligible in comparison.

> Which is faster:
>
> if .... else ...
> or:
> if (true) ...
> if (false) ...

I think, "if...else" should be slightly faster as only one condition needs
to be evaluated.

Greetings,
Thomas

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация