Home  >  Article  >  What is the difference between compilation and interpretation

What is the difference between compilation and interpretation

青灯夜游
青灯夜游Original
2021-06-29 12:49:2036539browse

Difference: 1. Compilation is to translate the source program into executable target code; the interpreter does not generate target code. 2. The interpreter can be used across platforms; the compiler is not cross-platform. 3. The interpreter can be modified at any time and it will take effect immediately; the compiler cannot. 4. The interpretation program has low running efficiency; the compiler execution speed is fast.

What is the difference between compilation and interpretation

The operating environment of this tutorial: Windows 10 system, Dell G3 computer.

Compilation is to translate the source program into executable target code, and translation and execution are separate; while interpretation is to complete the translation and execution of the source program at one time and does not generate storable target code. This is just an appearance. The biggest difference between the two is: for interpretation and execution, the control when the program is running lies with the interpreter and not the user program; for compilation and execution, the control at runtime lies with the user program.

The interpretation has good dynamic characteristics and portability. For example, when the interpretation is executed, the type of variables can be dynamically changed, the program can be modified, and good debugging diagnostic information can be inserted into the program. The interpreter is transplanted to a different system, the program can run on the system with the transplanted interpreter without modification. At the same time, the interpreter also has great shortcomings, such as low execution efficiency and large space occupation, because not only space must be allocated to the user program, but the interpreter itself also occupies valuable system resources.

The compiler compiles each statement of the source program into machine language and saves it into a binary file. In this way, the computer can directly run the program in machine language at runtime, which is very fast;

The interpreter only interprets the program one by one into machine language for the computer to execute, so the running speed is not as fast as the compiled program.

The difference between compilation and interpretation:

1. Different communication methods with computers

The interpreter does not generate object code, it takes out the statements in the source program one by one , interpret and execute at the same time; the interpreter interprets the source code file into machine language and hands it to the CPU for execution.

Compilation is to translate the source program into executable target code and execute the executable program file. Translation and execution are separated.

2. Different operating environments

The interpreter can be used across platforms, because the interpreter has already done a good job of interacting with different platforms, and the source code written by the user does not need to consider the differences. The source code can be executed directly on all platforms.

The cross-platform nature of the compiled program is not good. Different operating systems call the underlying machine instructions differently, and different machine code files need to be generated for different platforms.

3. Development convenience

The interpreter can be modified at any time and it will take effect immediately. After changing the source code, run it directly to see the effect

The compiler will modify the source code every time. All must be recompiled to generate machine code files

4. Running speed

Interpreted programs have low operating efficiency. All codes need to be interpreted and executed by the interpreter, and the speed is much slower than the compiled type.

Compiled programs execute quickly because your program code has been translated into machine language that the computer can understand.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What is the difference between compilation and interpretation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn