Some C++ code bases seem to compile much more slowly than others. It is hard to compare them directly because they very often have different sizes. Thus it is hard to encourage people to work on speed because there are no hard numbers to back up your claims.
To get around this I wrote a very simple compile time measurer. The code is available here. The basic idea is quite simple: provide a compiler wrapper that measures the duration of each compiler invocation and the amount of lines (including comments, empty lines etc) the source file had. Usage is quite simple. First you configure your code base.
CC='/path/to/smcc.py gcc' CXX='/path/to/smcc.py g++' configure_command
Then you compile it.
Finally you run the analyzer script on the result file.
The end result is the average amount of lines compiled per second as well as per-file compile speed sorted from slowest to fastest.
I ran this on a couple of code bases and here are the results. The test machine was a i7 with 16GB of ram using eight parallel compile processes. Unoptimized debug configuration was always chosen.
avg worst best Libcolumbus 287.79 48.77 2015.60 Mediascanner 52.93 5.64 325.55 Mir 163.72 10.06 17062.36 Lucene++ 65.53 7.57 874.88 Unity 45.76 1.86 1016.51 Clang 238.31 1.51 20177.09 Chromium 244.60 1.28 49037.79
For comparison I also measured a plain C code base.
avg worst best GLib 4084.86 101.82 19900.18
We can see that C++ compiles quite a lot slower than plain C. The main interesting thing is that C++ compilation speed can change an order of magnitude between projects. The fastest is libcolumbus, which has been designed from the ground up to be fast to compile.
What we can deduce from this experiment is that C++ compilation speed is a feature of the code base, not so much of the language or compiler. It also means that if your code base is a slow one, it is possible to make it compile up to 10 times faster without any external help. The tools to do it are simple: minimizing interdependencies and external deps. This is one of those things that is easy to do when starting anew but hard to retrofit to code bases that resemble a bowl of ramen. The payoff, however, is undeniable.