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.
There are many thing which will not yield much even after tedious optimization. There are two chief reasons for this:
What not to optimize
- 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
- 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
- Avoid branches as they will force the processor to speculate, which will result in significant performance losses, if the prediction is wrong.
- Optimize recursive functions and loops.
- Make 1-2 line functions inline, although many compilers do it themselves.
- 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.
- Try not to continually allocate and free memory.
- 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.
- Do not compromise modularity for speed except in cases where it is really important.
- Concise does not always mean fast.
- Do not use recursion where linear algorithms will do.
- Do not pass unrequired arguments to functions