Premature optimization is the root of all evil.

时间:2020-12-17 06:05:06

  For all of we programmers,we should always remember that "Premature optimization is the root of all evil". (Ref)

  When again,I come back to the 'Data Structure and Algorithm',following the algorithms that the .net provides,using the '.net reflector',I realise that I was too much care about something(for i am not work strict to memory and CPU circle limits).

  The issue I posted  "Would it cost any extra performance if multiple invoke methods that are overload?on the forum "*" shows the issue that confused me before.

  That issue comes from .net ArrayList class,such as the code below:

 public static void Copy(Array sourceArray, Array destinationArray, int length)
{
if (sourceArray == null)
{
throw new ArgumentNullException("sourceArray");
}
if (destinationArray == null)
{
throw new ArgumentNullException("destinationArray");
}
Copy(sourceArray, sourceArray.GetLowerBound(), destinationArray, destinationArray.GetLowerBound(), length, false);
}

  it actually calls

 Copy(sourceArray, sourceArray.GetLowerBound(), destinationArray, destinationArray.GetLowerBound(), length, false);
 internal static extern void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable);

as it is obvious.

  The method call between themselves can be 'inlined',or the opitimized by jitter.

  And remember that "Premature optimization is the root of all evil". Take much time to think about our own algorithms.