编译器和解释器
Before the Java and C# programming languages appeared, computer programs were only compiled or interpreted. Languages like Assembly Language, C, C++, Fortran, Pascal were almost always compiled into machine code. Languages like Basic, VbScript and JavaScript were usually interpreted.
在Java和C#编程语言出现之前,仅对计算机程序进行编译或解释 。 诸如汇编语言,C,C ++,Fortran和Pascal之类的语言几乎总是被编译成机器代码。 通常会解释诸如Basic,VbScript和JavaScript之类的语言。
So what is the difference between a compiled program and an Interpreted one?
那么,已编译程序和解释程序之间有什么区别?
编译中 ( Compiling )
To write a program takes these steps:
要编写程序,请执行以下步骤:
- Edit the Program 编辑程序
- Compile the program into Machine code files. 将程序编译为机器代码文件。
- Link the Machine code files into a runnable program (also known as an exe). 将机器代码文件链接到可运行的程序(也称为exe)。
- Debug or Run the Program 调试或运行程序
With some languages like Turbo Pascal and Delphi steps 2 and 3 are combined.
对于某些语言,例如Turbo Pascal和Delphi,将步骤2和3组合在一起。
Machine code files are self-contained modules of machine code that require linking together to build the final program. The reason for having separate machine code files is efficiency; compilers only have to recompile source code that have changed. The machine code files from the unchanged modules are reused. This is known as making the application. If you wish to recompile and rebuild all source code then that is known as a Build.
机器代码文件是机器代码的独立模块,需要链接在一起以构建最终程序。 拥有单独的机器代码文件的原因是效率。 编译器仅需重新编译已更改的源代码 。 来自未更改模块的机器代码文件将被重用。 这被称为制作应用程序。 如果您希望重新编译并重建所有源代码,则称为Build。
Linking is a technically complicated process where all the function calls between different modules are hooked together, memory locations are allocated for variables and all the code is laid out in memory, then written to disk as a complete program. This is often a slower step than compiling as all the machine code files must be read into memory and linked together.
链接是一个技术复杂的过程,其中将不同模块之间的所有函数调用挂钩在一起,为变量分配内存位置,并将所有代码布置在内存中,然后作为完整程序写入磁盘。 这通常比编译慢,因为必须将所有机器代码文件读入内存并将它们链接在一起。
口译 ( Interpreting )
The steps to run a program via an interpreter are
通过解释器运行程序的步骤是
- Edit the Program 编辑程序
- Debug or Run the Program 调试或运行程序
This is a far faster process and it helps novice programmers edit and test their code quicker than using a compiler. The disadvantage is that interpreted programs run much slower than compiled programs. As much as 5-10 times slower as every line of code has to be re-read, then re-processed.
这是一个更快的过程,它可以帮助新手程序员比使用编译器更快地编辑和测试他们的代码。 缺点是解释程序比编译程序运行慢得多。 由于必须重新读取然后重新处理每一行代码,速度降低了5-10倍之多。
输入Java和C# ( Enter Java and C# )
Both of these languages are semi-compiled. They generate an intermediate code that is optimized for interpretation. This intermediate language is independent of the underlying hardware and this makes it easier to port programs written in either to other processors, so long as an interpreter has been written for that hardware.
这两种语言都是半编译的。 它们生成针对解释进行了优化的中间代码。 这种中间语言独立于底层硬件,这使得将其中一个编写的程序移植到其他处理器变得更容易,只要已经为该硬件编写了解释器即可。
Java, when compiled, produces bytecode that is interpreted at runtime by a Java Virtual Machine (JVM). Many JVMs use a Just-In-Time compiler that converts bytecode to native machine code and then runs that code to increases the interpretation speed. In effect, the Java source code is compiled in a two-stage process.
Java在编译时会生成字节码,该字节码在运行时由Java虚拟机(JVM)解释。 许多JVM使用即时编译器将字节码转换为本地机器代码,然后运行该代码以提高解释速度。 实际上,Java源代码是分两步编译的。
C# is compiled into Common Intermediate Language (CIL, which was previously known as Microsoft Intermediate Language MSIL. This is run by the Common Language Runtime (CLR), part of the .NET framework an environment that provides support services such as garbage collection and Just-In-Time compilation.
C#被编译为通用中间语言(CIL,以前称为Microsoft中间语言MSIL。它由.NET框架一部分的公共语言运行库(CLR)运行,该环境提供了诸如垃圾收集和Just的支持服务-及时编译。
Both Java and C# employ speedup techniques so the effective speed is almost as fast as a pure compiled language. If the application spends a lot of time doing input and output like reading disk files or running database queries then the speed difference is barely noticeable.
Java和C#都采用加速技术,因此有效速度几乎与纯编译语言一样快。 如果应用程序花费大量时间进行输入和输出(如读取磁盘文件或运行数据库查询),则速度差异几乎不会引起注意。
这对我意味着什么? ( What Does this Mean to me? )
Unless you have a very specific need for speed and must increase the frame rate by a couple of frames per second, you can forget about speed. Any of C, C++ or C# will provide sufficient speed for games, compilers, and operating systems.
除非您对速度有非常特定的需求,并且必须将帧速率提高每秒几帧,否则您会忘记速度。 任何C,C ++或C#都可以为游戏,编译器和操作系统提供足够的速度。
翻译自: https://www.thoughtco.com/about-compilers-and-interpreters-958276
编译器和解释器