Saturday, October 16, 2010

General

Today I am just posting whatever comes to my mind. There is no specific topic. So these are just general optimization guidelines, which can be followed.

What not to optimize

There are many thing which will not yield much even after tedious optimization. There are two chief reasons for this:
  1. It may not need optimizing: optimizing parts of the program which hardly take any of the programs time will not improve the performance much. So only those parts should be optimized which are taking up a lot of the processors time
  2. It might have been automatically optimized. Many compilers align memory, optimize loops and use shifts instead of division where applicable. Optimizing these things will prove to be futile as it is already optimized.

General Optimization Guidelines

  1. Avoid branches as they will force the processor to speculate, which will result in significant performance losses, if the prediction is wrong.
  2. Optimize recursive functions and loops.
  3. Make 1-2 line functions inline, although many compilers do it themselves.
  4. Avoid fancy features like operator overloading and virtual functions, they are more inefficient. They can however e used in areas of programs which do not get executed frequently to make things more readable.
  5. Try not to continually allocate and free memory.
  6. At the same time watch out for memory leaks. For this see the performance tab of the task manager window and watch for a continual increase in memory usage.
  7. Do not compromise modularity for speed except in cases where it is really important.
  8. Concise does not always mean fast.
  9. Do not use recursion where linear algorithms will do.
  10. Do not pass unrequired arguments to functions

No comments:

Post a Comment