Automatically speed up compiling of source code on Linux

When you compile a program on Linux, the process usually goes

make install

The most time consuming process is usually the 'make' stage where the source code is compiled. Most computers today have CPUs with multiple cores, but by default 'make' only starts one thread and only one CPU core gets to do all work. If you have a dual-core CPU and start 'make' with parameter -j2, compilation is almost twice as fast.

To automatically use all available cores of your CPU, add this into your .bashrc:

NC=`cat /proc/cpuinfo | grep processor | wc -l`
alias make="make -j$NC"

This will automatically detect the number of CPUs/cores you have and will start enough threads to keep them all busy next time you type 'make' and you will have to wait much less.


Last updated: 30. Jun 2010
Page maintained by Jan Willamowius
Imprint/Impressum · Privacy/Datenschutz
English: Home | Linux | Perl | Java | Eiffel | Books | Music | Jan Willamowius | Updates | Site Map
Deutsch: Home | Badminton | ISBN-Suche | Musik-Suche | Rezepte | Jan Willamowius