[英]Does the speed of programming language depend on compiler?
I am trying to learn how computer programs work and have this question. 我正在尝试学习计算机程序是如何工作的并且有这个问题。 I often read articles like "C/C++ are faster than java" or "Java and C#: speed comparison".
我经常阅读诸如“ C / C ++比Java更快”或“ Java和C#:速度比较”之类的文章。 In all cases programs written in any language is translated to assembly language.
在所有情况下,以任何语言编写的程序都将翻译为汇编语言。 So, what is the reason of speed differences in those languages.
那么,这些语言中速度差异的原因是什么。 Does that mean, the compiler of one language generates better and faster assembly code ?
这是否意味着一种语言的编译器会生成更好,更快的汇编代码?
Sort of. 有点。
There are several reasons why speeds will differ between compilers/interpreters/programming languages, some of it having to do with the compiler, and some of it having to do with the language itself. 编译器/解释器/编程语言之间的速度会有所不同的原因有很多,其中一些与编译器有关,而某些与语言本身有关。
If your language is very high level, it'll have more overhead compared to C, which is very low level. 如果您的语言非常高级,那么与C(非常低级)相比,它将有更多开销。 (garbage collection is a good example of this).
(垃圾回收就是一个很好的例子)。 It becomes a tradeoff.
这成为一种折衷。 Do I want blazing fast binaries, or do I want to be able to write programs easily?
我想快速开发二进制文件,还是想轻松编写程序?
For example, PHP is designed to be used on web servers, and nobody in their right mind would try and use it to create a top-tier fps game. 例如,PHP被设计为可在Web服务器上使用,并且没有任何明智的人会尝试并使用它来创建顶级fps游戏。 Different languages are better suited for different tasks, and will be faster in some areas then in others.
不同的语言更适合于不同的任务,并且在某些领域会比其他领域更快。
While C/C++ may compile to assembly, languages like Java instead compile to bytecode and is run against the java virtual machine, for interoperability reasons. 尽管C / C ++可以编译为汇编语言,但出于互操作性的原因,像Java这样的语言却可以编译为字节码,并且可以针对Java虚拟机运行。 Once again, this is a tradeoff -- you gain portability at the expense of overhead.
再次,这是一个折衷方案-您以牺牲开销为代价获得了可移植性。
Furthermore, C/C++ doesn't even have to compile to assembly. 此外,C / C ++甚至不必编译即可汇编。 For example, enscriptem ultimately will compile C/C++ to Javascript so it can run on web browsers.
例如,enscriptem最终会将C / C ++编译为Javascript,以便它可以在Web浏览器上运行。
They're programs, and like all programs, have bugs and will improve (or degrade) over time. 它们是程序,并且像所有程序一样,都有错误,并且会随着时间的推移而改善(或降低)。 I could try writing a C compiler over the weekend, and I'd bet a million dollars that it would perform several orders of magnitude worse then a compiler/interpreter for the slowest language you can think of.
我可以尝试在周末编写C编译器,我敢打赌一百万美元,它会比您能想到的最慢的语言的编译器/解释器执行的性能差几个数量级。
Every year, researchers are writing and publishing papers on a new way to compile and make programs run faster. 每年,研究人员都以一种新的方式来撰写和发表论文,以使程序编译并使程序运行更快。 If a language is newer, it may not yet have had the time to fully apply every optimization available.
如果语言是较新的,则它可能还没有时间完全应用所有可用的优化方法。 (see above).
(往上看)。 Some optimizations may apply to only one kind of compiler/interpreter.
某些优化可能仅适用于一种编译器/解释器。
So, to summarize, the speed of a language is a mixture of the intrinsic features of the language itself, along with the maturity of the compiler/interpreter/platform used. 因此,总而言之,语言的速度是语言本身的内在特征与所使用的编译器/解释器/平台的成熟度的混合。
Compilers and interpreters are not some monolithic magical process that's constant between all programming languages -- they're all different, have different benefits and disadvantages, and are constantly in a state of flux. 编译器和解释器并不是在所有编程语言之间都保持不变的整体魔术过程-它们都是不同的,具有不同的优缺点,并且始终处于不断变化的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.