As a Gentoo user, I tried quite a few optimizations for the entire OS, and the Gentoo forums had an endless discussion about this. Some good flags for GCC can be found on the wiki .
In short, optimizing for size worked best on an old Pentium3 laptop with a limited bar, but on my main desktop machine with Core2Duo -O2 it gave the best results for everyone.
Also, a small script if you are interested in the most important x86 (32-bit) flags, the most optimized ones.
If you use gcc and really want to optimize a specific application, try ACOVEA . It runs a test suite, and then recompiles them with all possible combinations of compilation flags. Here is an example of using the Huffman encoding on the site (below is better):
A relative graph of fitnesses: Acovea Best-of-the-Best: ************************************** (2.55366) Acovea Common Options: ******************************************* (2.86788) -O1: ********************************************** (3.0752) -O2: *********************************************** (3.12343) -O3: *********************************************** (3.1277) -O3 -ffast-math: ************************************************** (3.31539) -Os: ************************************************* (3.30573)
(Note that he found that -O is the slowest in this Opteron system.)
Claes mogren
source share