You are here: Re: Is foreach the fastest way to do this? « PHP Programming Language « IT news, forums, messages
Re: Is foreach the fastest way to do this?

Posted by Carl Vondrick on 08/08/06 19:30

> I understand your desire to optimize the code. But some things just
> aren't worth the effort.

Agreed. Remember, when you optimize you should mostly look at the
complexity. Is it in polynomial or exponential time? If it's
exponential, then you have reason to worry.

For example, which of the following method is the worse? Best?

public function foo($m,$n)
{
for ($x = 0; $x < $m; $x++)
{
echo $x;
}
for ($y = 0; $y < $n; $y++)
{
echo $y;
}
}

public function foo($m,$n)
{
for ($x = 0; $x < $m; $x++)
{
for ($y = 0; $y < $n; $y++)
{
echo $y + $x;
}
}
}

The first one is better; the complexity of the first is O(n+m) vs O(n*m).

 

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

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