hhamm
hhamm

Reputation: 1581

Is compiling with C++11 way slower than with C++98?

I wanted to switch my project settings from C++98 to C++11 but I am quite skeptical because of the additional compile time.

My (quite big) project is about 800 files and the project is generated with cmake. In XCode with C++98 setting it compiles in roughly 15min on a i7 4GHz machine (ssd hard-disk, 16GB ram).

When switching to C++11 it takes about 25min (On Windows with Visual Studio 2013 it is even worse - nearly double the time!)

I don't know, something has to be completely wrong in my project setup or with my files, because no one is talking about additional compile times with C++11.

And yes I am using forward declarations, pimpl idioms, even tried double include guards and I removed a lot of template stuff that I don't need anymore thanks to C++11 (so compiling should be even faster, but it's not - it's slower!)

Is compiling with C++11 way slower than with C++98? And why is no one talking about this?

Upvotes: 2

Views: 1263

Answers (1)

Your question has no general answer, it is a matter of implementations.

Some compilers are faster than others. Phoronix claims that Zapcc is faster than its competitors (but I have no idea, I never heard of zapcc before).

I would guess that, for the same compiler, compiling C++11 style could be slower than compiling C++03 style (because C++11 introduced extra "syntax overloading" and auto, and feature like move constructors which might need extra support)

C++11 is known to be slow at compilation, in particular because standard headers (like <map> or <vector> ....) are bringing lots of material (and probably more in C++11 than in C++03).

For example, the following e.cc file (just two standard includes!):

#include <vector>
#include <map>

When compiling with g++ -std=c++11 -C -E e.cc | wc -l I am getting 41870 preprocessed lines, when compiling with g++ -std=c++03 -C -E e.cc | wc -l I am getting 15598 lines, both with GCC 5.3, on Linux/Debian/Sid/x86-64.

You might use precompiled headers (see this), and you could consider having not too small translation units (e.g. have your *.cc files contain a few thousands lines each, not a few dozens lines each).

Since cmake is generating Makefile-s for make, you might try a parallel build with make -j

Upvotes: 6

Related Questions