Faster builds with multithreaded make

Multiple core processors are the norm at this point, with four and now six cores being pretty much standard on desktop machines.  While the vast majority of software packages including pretty much all compilers are single-threaded, the build tool GNU Make has had the ability to use many threads for quite a while now with the -j flag.  While this requires makefiles to be written carefully to avoid implicit dependencies, the speedup can be quite significant.

As an example, here are the build-times for the clang C/C++ compiler and LLVM support libraries using from 1 to 10 threads.  The build system has a 4-core Intel Core i7 920 processor (2.6GHZ, Hyperthreading) which was state of the art about 3 years ago.

# Threads Build time

Speedup over
single-threaded build

1 2721 1.00
2 1442 1.89
3 994 2.74
4 772 3.52
5 742 3.67
6 716 3.80
7 688 3.95
8 659 4.12
9 661 4.12
10 659 4.12

As you can see, the end result is a more than 4x speedup simply by adding one flag to the command line.  Even though the machine only has four cores, there are substantial benefits to going up to 8 threads for the build (almost a two minute improvement going from 4 to 8 threads).  I suspect some of this may be due to Intel’s Hyperthreading (1 physical cores is presented to the OS as 2 logical processors).  I would also expect that newer multicore machines would see an even bigger bump, particular those with 6 or 8 cores.

Comments are closed.