On Fri, Mar 12, 2004 at 02:07:26AM -0800, Donald Burr wrote:
> A question occurred to me today.  How much difference does 'gcc -O<x>' 
> make in the speed of my system?

Usually the higher levels of -Ox optimisation make a lot less
difference than most people expect.  It depends very much on the
particular code that is being compiled exactly how much difference
those optimizations will make.  It's also the case that sometimes the
extreme optimizations will actually make the code run slower, and in
other cases it will cause the compiler to emit broken results --
that's particularly true of the FreeBSD kernel, for reasons I don't
profess to understand.
> I notice some ports that claim to not work properly if compiled with 
> -O<x> (the one that comes to mind right away is XFree86 4.x, but I've 
> seen others) and I am thinking of just turning OFF -O<x> option in my 
> /etc/make.conf.  I'm just wondering how much of an impact this will 
> have on system performance.

It always used to be said that the first rule of optimization was
"don't".  gcc(1) has modified that to be more like "don't use anything
higher than -O1" -- which is what the default setting is on FreeBSD.
"-O1" will get you the majority of the improvement in performance that
you can get by optimization, pretty much without the risks of bad

If you're looking for the best improvement in performance you can get,
the sensible thing to do is set the CPUTYPE variable correctly in
/etc/make.conf.  This effectively gives the compiler free reign to
exploit all of the capabilities of your CPU.  Plus it works very
effectively and without the problems of broken results that jacking up
the '-Ox' level has.
> FYI, my box is a Via C3 @ 800MHz with 128 MB RAM, and it basically 
> lives its life as an e-mail and Web server and gateway for my home 
> network.  (in other words it doesn't do any computing intensive stuff 
> like sequencing DNA or searching for aliens. :) )

Quite so.  Most of the processes you run will spend the vast majority
of the time waiting for IO requests to be fulfilled.  The most perfect
optimization immaginable can't make them run any faster.



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to