Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Mar 2004 11:44:55 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Donald Burr <dburr@borg-cube.com>
Cc:        List FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: How much difference does 'gcc -O<x>' make?
Message-ID:  <20040312114454.GA33032@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <101C5248-740D-11D8-B665-000A95B9AE7E@borg-cube.com>
References:  <101C5248-740D-11D8-B665-000A95B9AE7E@borg-cube.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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>'=20
> 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.
=20
> I notice some ports that claim to not work properly if compiled with=20
> -O<x> (the one that comes to mind right away is XFree86 4.x, but I've=20
> seen others) and I am thinking of just turning OFF -O<x> option in my=20
> /etc/make.conf.  I'm just wondering how much of an impact this will=20
> 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
results.

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.
=20
> FYI, my box is a Via C3 @ 800MHz with 128 MB RAM, and it basically=20
> lives its life as an e-mail and Web server and gateway for my home=20
> network.  (in other words it doesn't do any computing intensive stuff=20
> 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.

	Cheers,

	Matthew

--=20
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

--jRHKVT23PllUwdXP
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAUaK2dtESqEQa7a0RAru/AJ0f9xP9P0SX2nYPYIMSK+zUJNE4bwCfdKE5
360/hswaqaZ/VOy2vF6+Qt8=
=0lpc
-----END PGP SIGNATURE-----

--jRHKVT23PllUwdXP--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040312114454.GA33032>