

...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:

Run 10 kernel compilations and calculate the average time. Regular GCC build.

Optimized GCC build. The kernel in question is the latest stable Linux kernel. At this time, 2.4.20 remains the latest stable Linux kernel. The GCC used with this test is the latest stable gcc. At this time, 3.2.2 remains the lastest 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

./configure ; make BOOT_CFLAGS="optimization flags" bootstrap ; make install

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

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