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 Moot on 10/18/06 18:30

Sonnich wrote:
> Hi
>
> I have a costum function for a special search, which sort strings.
>
> This is currently the place where I can save a lot of time (~70%) if
> possible.
>
> So, which is faster:
>
> for($j = 0;$j<count($array);$j++)
> or
>
> $j = 0
> while($j<count($array))
> $j++;
>
> (well, I know that counting down is faster, so...
>
> $j = count($array)-1;
> while($j>=0)
> $j--;
> )
>
> ALSO
>
> Which is faster:
>
> if .... else ...
> or:
> if (true) ...
> if (false) ...
>
> BR
> Sonnich

I don't know any specifics on PHP's implementation of such things, so I
can't comment on that.

I can say, however, that if you need to focus on such trivial things in
order to improve performance, then maybe it's your algorithm that could
benefit from the attention instead.

Have you calculated the O (big-O) for the algorithm? Reducing it by at
least an order of magnitude would improve performance well over
whatever gain you may be able to squeeze out by changing a while to a
for.

You say you're sorting strings? Are you using a well-known sorting
algorithm, or something homegrown? Have you tried QuickSort?
MergeSort? HeapSort? InsertionSort (only good for sorting small
collections)?

QuickSort is about the cream of the crop, last I knew, though, so if
you're already using it, maybe you actually do need to look into the
performance differences between the control structures.

Moot

 

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

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