How fast is D compilation compared to C++?
Krzysztof Jajeśnica
krzysztof.jajesnica at gmail.com
Tue Sep 20 19:10:40 UTC 2022
On Tuesday, 20 September 2022 at 16:13:30 UTC, Ali Çehreli wrote:
> D's CTFE can make D compilation infinitely slow. Let's put
> anomalous cases aside...
>
> We say D compiles much faster than C++. Does anyone have any
> measurement or a gut feeling about the same program written in
> idiomatic C++ vs. idiomatic D? I think it may be 30 seconds vs.
> 5 seconds. I that a fair guess?
>
> Although a ballpark figure is good enough, precise measurements
> would be useful as well.
>
> Thank you,
> Ali
Out of curiosity I tried comparing build times for 2 personal
projects (one written in C++, the other written in D).
The C++ project is ~3k lines of code (including header files) and
takes ~8s to do a clean debug build with GCC+CMake (~2s for a
parallel build).
The D project is ~8k lines of code, takes ~1.4s to build with
DMD+DUB and ~3.6s to build with LDC. Unfortunately DUB seems to
be much worse than CMake at parallelising the build (or maybe my
spaghetti is a bit difficult to build in parallel) because
building with `dub --parallel` takes basically the same amount of
time.
Both projects are small video games using GLFW+OpenGL and very
few dependencies beyond that. The D project has 2-3 cases of
horrible CTFE/template abuse which is absent in the C++ project
and uses templates a bit more extensively. The C++ project has
more low level code.
Overall it seems that for single threaded debug builds D compiles
~15-20 times faster (per line of code) than C++ with DMD and ~5-7
times faster with LDC.
You should only treat these numbers as very rough estimates,
since I'm not exactly comparing apples to apples here.
More information about the Digitalmars-d
mailing list