Why do compilations take so long?

I am designing a programming language and one of the problems i was thinking was why do programming languages take long to compile. Assumed c++ takes a long time because it needs to parse and compile a header everytime it compiles a file. But i -heard- precompiled headers take as long? i suspect c++ is not the only language that has this problem.


一个C ++特有的问题使其变得非常慢,因为与几乎任何其他语言不同,您无法独立于语义分析来解析它。


Compiling is a complicated process which involves quite a few steps:

  • Scanning/Lexing
  • Parsing
  • Intermediate code generation
  • Possibly Intermediate code optimization
  • Target Machine code generation
  • Optionally Machine-dependent code optimization
  • (Leaving aside linking.)

    Naturally, this will take some time for longer programs.


    Precompiled headers are way faster, as has been known at least since 1988.

    The usual reason for a C compiler or C++ compiler to take a long time is that it has to #include, preprocess, and then lex gazillions of tokens.

    As an exercise you might find out how long it takes just to run cpp over a typical collection of header files---then measure how long it takes to lex the output.

    gcc -O uses a very effective but somewhat slow optimization technique developed by Chris Fraser and Jack Davidson. Most other optimizers can be slow because they involve repeated iteration over fairly large data structures.

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

    上一篇: C ++性能与Java / C#

    下一篇: 为什么编辑需要这么长时间?