|
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]
|