Compiler
High-level language(Source code) → Machine Language(Executable)
Therefore, running executable file does not require compiler to be installed.
Pros
- Because they can see all the code up-front, they can perform a number of analyses and optimizations when generating code that makes the final version of the code executed faster than just interpreting each line individually.
- Compilers can often generate low-level code that performs the equivalent of a high-level ideas like "dynamic dispatch" or "inheritance" in terms of memory lookups inside of tables. This means that the resulting programs need to remember less information about the original code, lowering the memory usage of the generated program.
- Compiled code가 interpreted code보다 일반적으로 더 빠르다. Instructions들이 program만을 위해 짜졌기 때문이다.
즉, interpreting overhead가 없다. - Protability가 좋다.
다른 H/W에서도 소스 코드를 건드릴 필요 없이 HW에 맞는 compile만 실행하면 된다.출처 : https://www.learncpp.com/cpp-tutorial/introduction-to-programming-languages/
Cons
- Some language features, such as dynamic typing, are difficult to compile efficiently because the compiler can't predict what's going to happen until the program is actually run. This means that the compiler might not generate very good code.
- Compilers generally have a long "start-up" time because of the cost of doing all the analysis that they do. This means that in settings like web browsers where it's important to load code fast, compilers might be slower because they optimize short code that won't be run many times.
Interpreter
Directly executes the instructions in the source code.
Therefore, interpreter must be installed on every machine where an interpreted program will be run.
However, more flexible than compilers.
Pros
- Because they can read the code as written and don't have to do expensive operations to generate or optimize code, they tend to start up faster than compilers.
- Because interpreters can see what the program does as its running, interpreters can use a number of dynamic optimizations that compilers might not be able to see.
Cons
- Interpreters typically have higher memory usage than compilers because the interpreter needs to keep more information about the program available at runtime.
- Interpreters typically spend some CPU time inside of the code for the interpreter, which can slow down the program being run.
Compilers and Interpreters
Because interpreters and compilers have complementary strengths and weaknesses, it's becoming increasingly common for language runtimes to combine elements of both. Java's JVM is a good example of this - the Java code itself is compiled, and initially it's interpreted. The JVM can then find code that's run many, many times and compile it directly to machine code, meaning that "hot" code gets the benefits of compilation while "cold" code does not. The JVM can also perform a number of dynamic optimizations like inline caching to speed up performance in ways that compilers typically don't.
Many modern JavaScript implementations use similar tricks. Most JavaScript code is short and doesn't do all that much, so they typically start off using an interpreter. However, if it becomes clear that the code is being run repeatedly, many JS engines will compile the code - or at least, compile bits and pieces of it - and optimize it using standard techniques. The net result is that the code is fast at startup (useful for loading web pages quickly) but gets faster the more that it runs.
One last detail is that languages are not compiled or interpreted. Usually, C code is compiled, but there are C interpreters available that make it easier to debug or visualize the code that's being run (they're often used in introductory programming classes - or at least, they used to be.) JavaScript used to be thought of as an interpreted language until some JS engines started compiling it. Some Python implementations are purely interpreters, but you can get Python compilers that generate native code. Now, some languages are easier to compile or interpret than others, but there's nothing stopping you from making a compiler or interpreter for any particular programming language. There's a theoretical result called the Futamura projections that shows that anything that can be interpreted can be compiled, for example.
첨언
주로 C, C++, Pascal은 compile되고
interpret되는 language는 대부분 Perl, Javascript 같은 script language다.
Reference
'C++' 카테고리의 다른 글
build, clean, rebuild, compile, run/start (0) | 2024.02.19 |
---|---|
What is Project and Workspace(or Solution)? (0) | 2024.02.19 |
C++ IDE 설치하기 (1) | 2024.02.19 |
C, C++ 개발 workflow (0) | 2024.02.19 |
C, C++의 철학과 역사 (0) | 2024.02.18 |