0

Possible Duplicate:
Why does C++ compilation take so long?

Coming from C# background, I can't help but notice that the speed of compilation for C++ and C# code differs a lot-- C# is very fast to compile, but C++ is comparatively slow-- very slow, in fact.

Why is this so?

Community
  • 1
  • 1
Graviton
  • 81,782
  • 146
  • 424
  • 602

1 Answers1

3

Two big reasons:

  1. C++ has to go and #include and parse all the header files (which means reading text files and interpreting them -- including templates -- and then expanding them right into your code) whereas C# uses pre-compiled information in the assembly DLLs.

  2. The potential C++ optimizations are way more far-reaching than the C# optimizations; they easily blow C# out of the water. The C# compiler never inlines a function call (that's the Just-In-Time compiler's job to do in the CLR), but C++ compilers frequently do that, and much more. The C++ compiler also has to do the JIT's compiler for the entire program at compile time (and then some!), so it's definitely slower.

I'd say that the biggest culprit is optimizations -- try turning off all optimizations in your compiler, and noticing the speedup.

user541686
  • 205,094
  • 128
  • 528
  • 886