What switch statement produces the least efficient machine code?
-
28-10-2019 - |
Question
I've got a question in one of my tests that asked me to answer what switch statement produce the least efficient machine code. The possible answers were O4, O1, O2, or O3. I don't event know what those are supposed to mean.
Solution
GCC Options That Control Optimization
-O -O1 Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
-O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O, this option increases both compilation time and the performance of the generated code.
-O3 Optimize yet more
-Os Optimize for size.
-Ofast Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard compliant programs