There are some optimization options of compilation that we can use.
3. –O3, optimization in speed and being hoped to have small size too.
4. –Os, optimization in size.
Ok, let we see by an example to see the difference among them.
1. Make a code2.c
int sum (int x, int y, int z)
int t = x+y+z;
2. Using command prompt to compile and produce an object file. Add -Ox before -c. For example, $ gcc -O2 -c code2.c. (See my posting about how to compile program using GCC in command prompt)
3. Disassemble the object file in command prompt. (See my posting about how to disassemble program)
4. See the result on picture below.
compilation using O1 optimization option
compilation using O2 optimization option
compilation using O3 optimization option
compilation using Os optimization optionNow you can see the differance of compilation result with different optimization option. The optimization will affect the speed and size of the program.