是什么使PHP比Java或C#慢? [英] What makes PHP slower than Java or C#?

查看:153
本文介绍了是什么使PHP比Java或C#慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直想知道的事情:如果所有这三种语言都被编译为字节码然后从那里执行,为什么PHP的速度比Java或C#慢?我知道,通常情况下PHP会根据每个请求重新编译每个文件,但是即使将APC(字节码缓存)放入图片中,其性能也无法与Java或C#相提并论(尽管APC大大提高了它).

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 that normally PHP recompiles each file with each request, but even when you bring APC (a bytecode cache) into the picture, the performance is nowhere near that of Java or C# (although APC greatly improves it).

我什至没有在网络上谈论这些语言.我在谈论他们在数字运算时的比较.甚至不包括启动时间或类似时间.

I'm not even talking about these languages on the web level. I am talking about the comparison of them when they're number crunching. Not even including startup time or anything like that.

此外,我没有根据此处的答复做出某种决定. PHP是我选择的语言;我只是对它的设计感到好奇.

Also, I am not making some kind of decision based on the replies here. PHP is my language of choice; I was simply curious about its design.

推荐答案

一个原因是PHP中缺少JIT编译器,就像其他人提到的那样.

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

另一个重要原因是PHP的动态类型.动态类型的语言总是比静态类型的语言慢,因为变量类型是在运行时而不是编译时检查的.结果,静态类型的语言(例如C#和Java)在运行时将显着提高,尽管它们通常必须提前编译.对于动态类型的语言,JIT编译器解决了这个问题,但是可惜的是,PHP没有内置的语言(尽管请参阅Facebook的 HHVM (用于PHP的第三方JIT的示例).

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 (though see Facebook's HHVM for an example of a third-party JIT for PHP).

这篇关于是什么使PHP比Java或C#慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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