Posts

Showing posts with the label Optimization

GCC Extenstion

GCC has given some additions to its existing functionality. Please find more details from the below link. http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/index.html

What is Code Bloat?

Code bloat refers to the unnecessarily generated code which effects the performance of the program. It makes program run slow and uses unncessary resources. Example for code bloat is using in-line functions for long peice of code. Some naive compilers of C++ will make different function of each type if a template is defined, which causes so much of unnecessary code which is never executed. This un used code is called as dead code.

Optimizing tips for C++

Few tips in C++ to optimize the code: --> Data Types: 1. Using of 'int' instead of char or short. Its good to use the data type 'int' instead of 'char' or 'short' wherever possible. Explanation: Data type 'int' is always the native type for the machine. --> Operators 1. Arithmetic operations. Addition is always faster than multiplication and multiplication is faster than division. And bit wise operations are faster than any other Operation. Where ever possible see if you can write the optimized code. This optimized code, will save a lot of time and system resources.  2. Use 'op='. Wherever possible, use 'op=' in favour of 'op'. For example, use myShape += value; rather than myShape = myShape + value; Explanation:  The first version is better than the second because it avoids creating a temporary object. 3. if-else. Every 'if'  should have corresponding 'else' . Eg: if(a>b) {      someth...