[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]
LINUX GAZETTE
...making Linux just a little more fun!
Optimizing GCC
By Justin Piszcz

I have a Pentium 3 866MHZ CPU. After reading the freshmeat article on optimizing GCC a few days ago, it got me thinking. So I posed the following question: How much faster would gcc compile the kernel if gcc itself was optimized? I chose to benchmark kernel compilation times, because I think it is a good benchmark, and many other people also use it to benchmark system performance. Also, at one point or another, most Linux users will have to take the step and compile the kernel, so I thought I'd benchmark something that is useful and something that people have a general idea of how long it takes to compile without optimizations. So my test is comprised of the following:

  1. Run 10 kernel compilations and calculate the average time.
  2. The kernel in question is the latest stable Linux kernel.
  3. The GCC used with this test is the latest stable gcc.

With an non-optimized compiler, (configure;make;make install)
Average of 10 'make bzImage':
TIME: 12.42 minutes (762 seconds)

With an optimized compiler, I specifically used:

-O3 -pipe -fomit-frame-pointer -funroll-loops -march=pentium3 -mcpu=pentium3
-mfpmath=sse -mmmx -msse
In case you are wondering how to do this, it is in the FAQ of the gcc tarball. The following line is what I used:
   ./configure ; make BOOT_CFLAGS="optimization flags" bootstrap ; make install
Average of 10 'make bzImage'
TIME: 9.31 minutes (571 seconds)

I compile almost everything I run on my Linux box. I use a package manager called relink to manage all of my installed packages.

Optimizing the compiler alone: offers a speed increase of: 33% (or 3:11 minutes, 191 seconds faster). This may not seem like a lot, but for compiling big programs, it will significantly reduce compile time making those QT & Mozilla builds that much faster :) The actual test consisted of this:

cd /usr/src/Linux

for i in `seq 1 10`

do

  make dep

  make clean

  /usr/bin/time make bzImage 2>> /home/war/log

done
In case you're wondering about the time elapsed per build and how much the CPU was utilized, here they are:
No Optimization (Standard GCC-3.2.2):

   720.88user 34.54system 12:43.97elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k

   719.06user 35.69system 12:42.09elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   719.14user 34.37system 12:39.64elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   720.52user 36.42system 12:46.68elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k

   721.07user 33.86system 12:41.59elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   718.95user 35.65system 12:41.31elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   721.83user 36.26system 12:51.54elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k

   720.29user 34.18system 12:40.63elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   719.14user 34.80system 12:39.19elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   721.16user 33.88system 12:41.93elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k


Optimized Compiler (GCC-3.2.2 w/ "-O3 -pipe -fomit-frame-pointer -funroll-loops
-march=pentium3 -mcpu=pentium3 -mfpmath=sse -mmmx -msse")

   532.09user 33.62system 9:32.76elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k

   531.57user 32.92system 9:29.25elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   532.99user 33.12system 9:31.18elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   532.58user 33.16system 9:30.57elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   533.18user 32.96system 9:31.34elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   534.01user 32.21system 9:32.50elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k

   532.59user 33.41system 9:31.56elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   532.76user 33.68system 9:32.01elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   534.19user 32.54system 9:31.92elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k

   534.11user 32.76system 9:32.40elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
Note: I realize some of the optimizations, most specifically (-fomit-frame-pointer) may not be a good optimization feature, especially for debugging. However, my goal is to increase compiler performance and not worry about debugging.

 


Copyright © 2003, Justin Piszcz. Copying license http://www.linuxgazette.com/copying.html
Published in Issue 88 of Linux Gazette, March 2003

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]