How I can compile my project with optimizations turned on and see what optimizations changed in my code.
For example:
My original code:
printf("Test: %d",52);
for (int empty=0;i<100000;i++) {
//Nothing here
}
Now when I compile my code with optimzations ,I want to see: (I think it’ll be like that)
printf("Test: 52");
The compiler doesn’t
optimizemodify the source code (what you’ve shown in your question), but the binary, which consists of asm instructions.How you turn optimization on and off depends on the compiler, so you’ll have to refer to its documentation.
In MSVS, you can choose this option from the top toolbar – look for
Debug(un-optimized) vsRelease(optimized). You can see the binary code by stepping through the code with the debugger, right click -> show dissasembly.Your code, for example, generates:
Without optimizations:
With optimizations: