Search code examples
compiler-constructionprogramming-languagesinterpreted-language

Language interpreted from source code vs. bytecode in Web


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


Solution

  • 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.