What makes PHP slower than Java or C#?

后端 未结 8 754
耶瑟儿~
耶瑟儿~ 2020-12-14 16:10

This is something I\'ve always wondered: Why is PHP slower than Java or C#, if all 3 of these languages get compiled down to bytecode and then executed from there? I know th

相关标签:
8条回答
  • 2020-12-14 16:38

    There is no way an interpreted language can be faster than a compiled language or even a JIT language under trivial conditions.

    Unless your test program consists of printing out "Hello Worlds" if you are concerned about speed, stick with C# or Java.

    0 讨论(0)
  • 2020-12-14 16:39

    One reason is the lack of a JIT compiler in PHP, as others have mentioned.

    Another big reason is PHP's dynamic typing. A dynamically typed language is always going to be slower than a statically typed language, because variable types are checked at run-time instead of compile-time. As a result, statically typed languages like C# and Java are going to be significantly faster at run-time, though they typically have to be compiled ahead of time. A JIT compiler makes this less of an issue for dynamically typed languages, but alas, PHP does not have one built-in. (Edit: PHP 8 will come with a built-in JIT compiler.)

    0 讨论(0)
提交回复
热议问题