Other Links
http://www.codeproject.com/cpp/C___C...timization.asp
There is a good link.
About Optimization
The optimization, I am referring to is the runtime speed of the program. Think FPS. I am not speaking of memory optimization, bandwidth optimization, development time optimization or any other kind of optimization unless it increases the raw speed of an application. It is like tuning up a car engine to make it run as fast as possible.
Why optimization is important
I particularly don’t use optimization much because the process is time consuming. However, there are times when the need for optimization is high. Take for example, developing a game to increase fps, or developing a research program that takes many hours before returning the result. Due to laziness and lack of development time I can find ways to bypass these problems, such as running a research program overnight while I sleep, or develop a game using lesser graphics and physics data. Eventually I will have to put more data in a game or run a longer research program. These stress the need for optimization.
How important is optimization
Even when optimization is needed it is good to have an idea of the amount of optimization that you will achieve from a particular code change e.g. 1%, 5% or 10% increase in speed. This can give you an idea of the worth of the optimization, and if that is worth your efforts.
When optimization is needed but not used
For testing purposes, when you are testing the speed of a particular module, you can call that function a lot of times in an unoptimised way.
Factors Affecting Optimization
* The type of processor architecture
* The complier (different compliers build code with very small variances)
* The build settings (a compiler can build different code from the same source depending on the build settings)
Run time is affected by:
* The OS
* Background applications and free memory
Automatic Optimizations
Compilers can optimize code, e.g. remove unused logic. Sometimes it sets up assembly instructions so that the processor has a better means of executing parallel instructions and pre-fetch other instruction and avoid lags. Sometimes it takes stretched out code and reduce it to compact assembly instructions by organizing them and making multiple operations on a single data before it is done with that data. The source code may need to be written more compact or organized. Not all compilers do automatic optimization the same way. Personally, I do not mess with this level of optimization; if I am that pressed for speed then I would spend the extra time and effort in assembly language; I will try to do as much low level optimization in future posts.