从源代码解释的语言与 Web 中的字节码

发布于 2024-10-06 17:12:35 字数 278 浏览 0 评论 0原文

假设程序是用两种不同的语言编写的:

  1. 从源代码解释的语言(例如 PHP)
  2. 从字节码解释的语言(例如 Java)。

这两个程序的功能完全相同(为简单起见,假设它们都只输出一行文本)。

语言 (2) 会比 (1) 更快吗?

理论上,如果两个站点提供相同的功能,但一个使用 PHP 构建,另一个使用 Java (JSP) 构建,我可以得出这样的结论吗? ,基于Java的网站会更快吗?

乔尔

Assuming a program is written in 2 different languages:

  1. In a language interpreted from source code (PHP for example)
  2. In a language interpreted from bytecode (Java for example).

The two program do exactly the same (for simplicity, lets say they both just output one line of text).

Will language (2) be faster than (1)?

Can I conclude that in theory, in a case where two sites offer the same functionality, but one built with PHP while the other with Java (JSP), the Java based site will be faster?

Joel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2024-10-13 17:12:35

不,对此根本没有任何保证。这是生成中间字节码的正常编译过程的一部分。 PHP 只是获取源码 ->字节码->一次性执行,而 Java 则源代码 ->文件->字节码->执行。没有太大区别。主要区别在于后端——支持两种语言的 JIT 的有效性如何,程序的静态部分与动态部分(例如类型)有多少。

更重要的是,花费和下载必要的数据包或数据库交互的时间可能会主导网站性能,而不是支持语言。

No, there's no guarantees about this at all. It's part of the normal compilation process to produce an intermediary bytecode. PHP just goes source -> bytecode -> execution all in one go, whereas Java goes source -> file -> bytecode -> execution. There's not much difference. The primary difference will come in backends- how effective is the JIT backing both languages, how much of the program is static versus dynamic (types, for example).

More importantly, the time spent up and downloading the necessary packets or database interactions will likely dominate the website performance, not the backing language.

余厌 2024-10-13 17:12:35

对于文本解释器与字节代码解释器,一般来说,“更快”的解释器将是花费更多技术将源代码编译为优化的机器代码的解释器。这假设要执行的计算量主导“编译”代码所需的时间。

对于网页来说,这可能很重要,也可能不太重要,因为您的网页可能没有太多计算要做。 (大多数网页都花时间等待用户输入:) 对于您的一行示例,我认为没有人关心。

对于 PHP 与 Java 的比较,我认为您会发现 Java 在整体速度方面毫无疑问是赢家。 PHP HipHop 编译器试图赶上大多数 Java 实现的通用即时编译器功能。

For text vs. byte code interpreters, in general, the "faster" one will be the one with more technology spent compiling the source code to optimized machine code. This assumes that the amount of computation to do dominates the amount of time it takes to "compile" the code.

Fro web pages, it may or may not matter much, since your web pages may not have a lot of computation to do. (Most web pages spend their time waiting for user input :) For your one line example, I don't think anybody cares.

For PHP vs. Java, I think you will find that Java is a hands down winner in terms of overall speed. The PHP HipHop compiler is an attempt to catch up with the general Just-in-time compiler capabilities of most Java implementations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文