Code tuning is basically a way of improving program's performance .It refers to changing the implementation of a design rather than changing the design itself.
An appealing reason for code tuning is that programmers see the software world from code's point of view. From that point of view, "better" code means better software. It is also appealing because mastering the art of writing efficient code is a rite of passage to becoming a serious programmer.
Optimization of code is done in two ways:
Improving Speed only:
- Cache frequently used values.
- Use sentinels in search loops etc.
- Jam loops.
- Pre-compute results.
- Initialize data at compile time.
- Substitute table lookups for complicated logic.
- Use integers instead of floating point variables etc.
If you want your program to be portable, techniques that improve performance in one environment can degrade it in others. If you change or upgrade compilers, the new compiler may automatically optimize code the way you were hand tuning it-your work will have been wasted. Even worse, your code tuning may defeat compiler optimizations that are designed to work with well-structured code.
Code tuning doesn’t always improve code readability, changes that you make are not meant to improve the internal structure of a software
No one but you and other programmers usually care how tight your code is. Nonetheless, within the programming culture, writing micro-efficient code proves you're cool !!