For those that have never benchmarked the performance differences between GCC's different optimization levels, here are some recent test results comparing the performance differences when using an AMD FX-8150 processor with GCC 4.7.2.
These are just some straightforward benchmarks to share showing the performance differences of GCC 4.7.2 from the AMD FX-8150 Bulldozer system when changing out the optimization flags and then having the Phoronix Test Suite re-build the tests each time followed by letting it do its automated benchmarks.
For those unfamiliar with the different optimization flags, see the GCC optimize options documentation. The tested flags used in this article include:
-O0 - Reduce compilation time and make debugging produce the expected results. This is the default.
-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. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options.
-Os - Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Ofast - Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on -ffast-math and the Fortran-specific -fno-protect-parens and -fstack-arrays.
Only the generated binary performance is being compared in this article and not focusing upon the compilation time (though there is one result shared in this article of the PHP compilation time) or generated binary size.