Why does C# compile much faster than C++?

I notice on the same machine, it takes C# much less time than C++ to compile. Why?

NOTE1: I have not done any scientific benchmark.

NOTE2: Before anyone says this isn't programming related, I am implementing a parser, I am finding what I can do from the get go to increase compile speed.

NOTE3: I have a similar question Why do compilations take so long?. This question is asking on the specific difference from C/C++ to C#. It's obvious a simple language would be quicker to compile than a complex language, but C and C# are both complex languages.

my takeaway: 1) C/C++ is SLOW from preprocessor and headers. 2) alot of headers causes a lot more data to parse. especially when each file can use the preprocessor can change code 3) C# defer some compilation to program startup 4) IL instructions are simple, machine is not


看看这篇文章:为什么C ++编译需要这么长时间?


There are two separate issues to consider - the number of phases of processing, and the complexity of targeting.

A typical C++ compilation involves a number of phases (though these may be run concurrently) where the Preprocessor handles directives and macros, then the C++ compiler itself processes the resulting code. It's pretty common for the preprocessor to generate output that is significantly bigger, code that all needs to be parsed and processed by the actual compiler.

Also, keep in mind that the C++ compiler will be targeting x86 or x64 machine language - handling all optimization up front, and attempting to make best use of hardware that isn't really optimized at OO style development.

In contrast, the C# compiler is targeting Microsoft Intermediate Language (MSIL), a higher level machine-code-like platform that was designed to be used for OO development. Many of the constructs provided by C# map directly into IL instructions, making compilation really easy. A fair chunck of optimization and other activity is deferred until startup of the actual program, at which point it's optimized for the exact available machine.


Because C++ compiles to machine code, while C# to byte code. Have you noticed the lag when you first start your .NET program. It is when the byte code gets JITed (compiled to machine code).

链接地址: http://www.djcxy.com/p/14964.html

上一篇: visual studio 2012编译时间

下一篇: 为什么C#编译比C ++快得多?