3

I have a visual studio 2019 C++ project that I am converting to clang and I noticed that the clang version compiles quite a bit slower as reported by the -ftime-report switch, which on average says that clang takes about 1700ms to compile while the VS2019 version takes only 1150ms to compile. No precompiled headers are involved.

Note that I am building the clang version directly from the command-line by calling clang++.exe directly with the following (most relevant) flags:

-std=c++14 -g -c

The VS2019 version uses the following flags:

/permissive- 
/GS 
/W3 
/Zc:wchar_t 
/Qspectre 
/Zi 
/Gm- 
/Od 
/sdl 
/Fd"x64\Debug\vc142.pdb" 
/Zc:inline 
/fp:precise 
/D "_DEBUG" 
/D "GAMECODE_EXPORTS" 
/D "_WINDOWS" 
/D "_USRDLL" 
/D "_WINDLL" 
/D "_UNICODE" 
/D "UNICODE" 
/errorReport:prompt 
/WX- 
/Zc:forScope 
/RTC1 
/Gd 
/MDd 
/std:c++14 
/FC 
/Fa"x64\Debug\" 
/EHsc 
/Fo"x64\Debug\" 
/debug
/diagnostics:column 

What could be causing such a big difference to make VS2019 faster? Does MsBuild do something special to speed up the compilation that my simple command-line invocation of the clang compiler doesn't do?

mbl
  • 805
  • 11
  • 18
  • You don't seem to be using `/debug`. – arrowd Dec 04 '19 at 03:36
  • You're right, I added `/debug` but the compile time didn't change for MSVC. – mbl Dec 04 '19 at 03:48
  • 1
    AFAIK, `/Debug` is actually `/D ebug`, so it isn't making difference. Use lowercase `/debug`. – arrowd Dec 04 '19 at 05:04
  • That didn't seem to add any extra time either. However I tried compiling using the `clang-cl` toolchain inside VS, and the build times look very similar to what I get from clang in the command-line. So it seems that clang is a bit slower on Windows – mbl Dec 04 '19 at 05:08
  • 2
    **Why does compilation time matters? A 2 second build time is really small** (try buildijng `clang` from its [source code](http://releases.llvm.org/download.html); it could take hours). I did wrote programs which took an hour of CPU time to build. BTW, did you try to use `clang` on a Linux distribution? It might be a little bit faster – Basile Starynkevitch Dec 04 '19 at 05:10
  • Also, learn to use a [build automation](https://en.wikipedia.org/wiki/Build_automation) system like [make](https://www.gnu.org/software/make/), [ninja](http://ninja-build.org/), [omake](http://projects.camlcity.org/projects/omake.html), etc... – Basile Starynkevitch Dec 04 '19 at 05:13
  • And I strongly recommend compiling with `clang -g -Wall` – Basile Starynkevitch Dec 04 '19 at 05:14

0 Answers0