为什么解释型语言很慢? [英] Why are Interpreted Languages Slow?

查看:66
本文介绍了为什么解释型语言很慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读解释型语言的优缺点,最常见的缺点之一是速度慢,但为什么解释型语言的程序慢?

I was reading about the pros and cons of interpreted languages, and one of the most common cons is the slowness, but why are programs in interpreted languages slow?

推荐答案

本机程序使用为它们运行的​​处理器编写的指令运行.

Native programs runs using instructions written for the processor they run on.

解释型语言就是解释型".一些其他形式的指令由运行时读取和解释,然后执行本机机器指令.

Interpreted languages are just that, "interpreted". Some other form of instruction is read, and interpreted, by a runtime, which in turn executes native machine instructions.

这样想.如果您可以用您的母语与某人交谈,这通常比让口译员将您的语言翻译成其他语言以供听众理解要快得多.

Think of it this way. If you can talk in your native language to someone, that would generally work faster than having an interpreter having to translate your language into some other language for the listener to understand.

请注意,我上面描述的内容是针对在解释器中运行语言的情况.许多语言都有解释器,也有用于构建本机机器指令的本机链接器.速度降低(无论其大小)仅适用于解释的上下文.

Note that what I am describing above is for when a language is running in an interpreter. There are interpreters for many languages that there is also native linkers for that build native machine instructions. The speed reduction (however the size of that might be) only applies to the interpreted context.

因此,说语言很慢是有点不正确的,而是它运行的上下文很慢.

So, it is slightly incorrect to say that the language is slow, rather it is the context in which it is running that is slow.

C# 不是解释型语言,尽管它使用了中间语言 (IL),但在执行前会 JIT 到本机指令,因此它具有一些相同的速度降低,但不是所有这一切,但我敢打赌,如果您为 C# 或 C++ 构建了一个成熟的解释器,它的运行速度也会变慢.

C# is not an interpreted language, even though it employs an intermediate language (IL), this is JITted to native instructions before being executed, so it has some of the same speed reduction, but not all of it, but I'd bet that if you built a fully fledged interpreter for C# or C++, it would run slower as well.

澄清一下,当我说慢"时,这当然是一个相对的术语.

And just to be clear, when I say "slow", that is of course a relative term.

这篇关于为什么解释型语言很慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆