LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-03-2004, 04:31 PM   #1
eken_i_leken
LQ Newbie
 
Registered: Aug 2004
Location: Sweden
Distribution: Slackware
Posts: 5

Rep: Reputation: 0
CFLAGS -O2 -O3 does it realy matter?


Hello

I just wonder how much difference the -O argument CFLAG really makes. Usually -O2 is standard, as I understand, for most systems i486. I have used -O3 , but I cant make any difference in performance. I have even read somewhere that it's possible to use up to -O9 Optimization. I know that some optimization only implies on newer CPUs.

I just wonder if it realy is worth putting effort to this matter in reality.

Amd Athlon XP 2000+
 
Old 08-03-2004, 05:21 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
-O2 and -O3 does usually make a difference.

In general:
-O1 performs only optimisations that don't effect the compile time much.
-O2 performs optimisations without trading space for speed
-O3 performs maximal speed optimisation
-Os tries to make the executable as small as possible

-O4 through -O9 are just legacy synonyms for -O3

Obviously, the effects that you will get performance wise depend largely on what code you are optimising. Programs that read and write a lot to hardware (like a disk) without doing much computation won't generally notice much difference (as the bottle-neck here is waiting for the hardware).

If you want speed, use scalable algorithms (merge-sort rather than bubble-sort). For real speed, use assembler on the bits that get run a lot.

— Robert J. Lee
 
Old 08-03-2004, 09:02 PM   #3
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
yea it does make a difference -- also you should be using
-march=athlon-xp

compiler optimizations are actually quite application specific as far as performance goes.

-g is to be avoided at all costs unless you need debugging symbols for some reason

The downside to all this fun is some programs will not compile and or run properly with agressive optimizations..

example:
i compiled cvs with
-march=pentium4 -O3 -funroll-loops -ftracer -momit-leaf-frame-pointer -fprefetch-loop-arrays
which is generally what i use for my P4 system all the time
later when i go to use it everything i do make it segfault and i have to recompile without the flags.

for some applications that are specific to a certain type of calculations -O3 can actually be slower than
-O2
or -O2 slower than -O1 with just some of the flags included in but not all.
for instance this is alot better (30% better) at math on my system than what i put above
-march=pentium4 -O1 -finline-functions -mieee-fp -fforce-mem -fschedule-insns -fstrict-aliasing -fomit-frame-pointer -fmove-all-movables -funroll-loops -ftracer -momit-leaf-frame-pointer -fprefetch-loop-arrays

for some real fun use this
to figure out what exactly works best on your system
it is time well spent (if you'r a real nerd and like this sort of thing)
 
Old 08-05-2004, 06:46 AM   #4
ramen
Member
 
Registered: Nov 2002
Location: Yorkshire,England
Distribution: Slackware, Slamd64
Posts: 47

Rep: Reputation: 15
What version of GCC are you planning on using? If you're using 3.4, don't combine -O3 and -ftracer, as it causes problems
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Frame realy interface arenasa Linux - Networking 1 03-28-2005 01:08 AM
cflags exodist Linux - Software 2 01-14-2005 07:44 PM
Using CFLAGS and other options vexer Linux From Scratch 7 08-18-2004 09:04 AM
Realy Realy Need some basics Essay Slackware 7 04-26-2004 04:59 PM
How to REALY shut down the computer? caphclimber Linux - Software 8 09-08-2003 08:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration