LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   gcc optimization flags: rules of thumb (https://www.linuxquestions.org/questions/linux-software-2/gcc-optimization-flags-rules-of-thumb-195434/)

elyk 06-19-2004 04:27 PM

gcc optimization flags: rules of thumb
 
I've looked over some of the gcc optimization settings, such as -O2, -O3, etc., and tried to understand exactly what they do. What are some of the best settings to use? Are there any rules of thumb for what settings to use when compiling certain programs or kernels?

mugstar 06-19-2004 04:49 PM

There's a good section on optimisation flags in the Gentoo docs, you could also try http://www.freehackers.org/gentoo/gc...flag_gcc3.html

elyk 06-20-2004 12:18 AM

I'm just a little wary of using the power of -O3, or maybe even -O2. What do slackware packages use by default?

[edit] I guess I should ask, what do the "official" slackware packages use by default? [/edit]

I think they're all stripped, just try to find an ELF executable in /usr/bin that's not.

qwijibow 08-04-2004 11:49 PM

i dont know how i can possibly explain it any more simply than the gcc man pages.. but anyways..

-O0 = no optimisation
-O1 = perform optimisations that will not increace compile time significantly
-O2 = perform optimisations that will not increace binary size significantly
-O3 = apply all optimisations
-Os = optimise binary size, (almost as optimised as -O2)

rule of thumb....
if compile time is an issue, use -O1
if binary file size is an issue, but compile time is not, use -O2
if time, nor binary file size is an issue, use -O3
if file size IS an issue, use -Os
if you get seg faults, or have bad hardware, recompile with a lover optimisation.


All times are GMT -5. The time now is 07:56 PM.