As开发者_如何学Pythonsuming a program is written in 2 different languages:
- In a language interpreted from source code (PHP for example)
- 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
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.
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.
精彩评论