代码执行速度:ASP.NET-MVC 与 PHP [英] Speed of code execution: ASP.NET-MVC versus PHP

查看:18
本文介绍了代码执行速度:ASP.NET-MVC 与 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与一位同事就此进行了友好的争论,我个人的观点是,ASP.NET-MVC 编译的 Web 应用程序比用 PHP 编写的同一个项目运行更有效/更快.我的朋友不同意.

I have a friendly argument going on with a co-worker about this, and my personal opinion is that a ASP.NET-MVC compiled web application would run more efficiently/faster than the same project that would be written in PHP. My friend disagrees.

不幸的是,我没有任何可靠的数据可以用来支持我的论点.(他也没有)

Unfortunately I do not have any solid data that I can use to back up my argument. (neither does he)

为此,我试图通过谷歌寻找答案,试图找到证明他错的证据,但大多数时候争论变成了更好的开发平台、成本、安全功能等......对于为了这个论点,我真的不在乎这些.

To this, I tried to Google for answers to try and find evidence to prove him wrong but most of the time the debate turned into which platform it is better to develop on, cost, security features, etc... For the sake of this argument I really don't care about any of that.

我想知道堆栈溢出社区如何看待使用 ASP.NET 和 MVC 开发的网站与使用 PHP 开发的完全相同的网站的原始速度/效率?

I would like to know what stack overflow community thinks about the raw speed/efficency of websites in general that are developed in ASP.NET with MVC versus exactly the same website developed with PHP?

是否有人在实际场景中比较了两种技术的性能?

Does anyone have any practical examples in real-world scenarios comparing the performance of the two technologies?

(我意识到对于你们中的一些人来说,这很可能是一个无关紧要的论点,也许是愚蠢的论点,但这是一个论点,我仍然希望听到这里优秀人士的答案)

推荐答案

很难进行比较,因为各个堆栈的差异意味着您最终会以不同的方式做同样的事情,而如果您为了比较而做同样的事情这不是一个非常现实的测试.

It's a hard comparison to make because differences in the respective stacks mean you end up doing the same thing differently and if you do them the same for the purpose of comparison it's not a very realistic test.

我喜欢的 PHP 以最基本的形式加载每个请求,解释然后丢弃.它在这方面非常像 CGI(考虑到它大约有 15 年的历史,这并不奇怪).

PHP, which I like, is in its most basic form loaded with every request, interpreted and then discarded. It is very much like CGI in this respect (which is no surprise considering it is roughly 15 years old).

多年来,为了提高性能进行了各种优化,例如最引人注目的是使用 APC 的操作码缓存(以至于 APC 将成为 PHP 6 的标准部分,而不是像现在这样的可选模块).

Now over the years various optimisations have been made to improve the performance, most notably opcode caching with APC, for example (so much so that APC will be a standard part of PHP 6 and not an optional module like it is now).

但 PHP 脚本基本上是暂时的.会话信息(通常)是基于文件且互斥的(session_start() 阻止其他脚本访问同一用户会话,直到 session_commit() 或脚本完成),而在 ASP.NET 中并非如此.除了会话数据之外,在 ASP.NET(或与 ASP.NET 更相似的 Java)中的应用程序上下文中拥有对象相当容易(并且正常).

But still PHP scripts are basically transient. Session information is (normally) file based and mutually exclusive (session_start() blocks other scripts accessing the same user session until session_commit() or the script finishes) whereas that's not the case in ASP.NET. Aside from session data, it's fairly easy (and normal) to have objects that live within the application context in ASP.NET (or Java for that matter, which ASP.NET is much more similar to).

这是一个关键的区别.例如,PHP 中的数据库访问(使用 mysql、mysqli、PDO 等)是暂时的(尽管有持久连接),而 .Net/Java 几乎总是使用持久连接池并在此基础上构建 ORM 框架等,超出任何特定请求的缓存.

This is a key difference. For example, database access in PHP (using mysql, mysqli, PDO, etc) is transient (persistent connections notwithstanding) whereas .Net/Java will nearly always use persistent connection pools and build on top of this to create ORM frameworks and the like, the caches for which are beyond any particular request.

作为字节码解释平台,ASP.NET 理论上更快,但 PHP 所能做的限制如此之高,以至于对大多数人来说无关紧要.例如,互联网上访问量最大的 20 个站点中有 4 个是 PHP.当您开始扩展时,开发速度、稳健性、运行环境的成本等往往比任何理论速度差异都重要得多.

As a bytecode interpreted platform, ASP.NET is theoretically faster but the limits to what PHP can do are so high as to be irrelevant for most people. 4 of the top 20 visited sites on the internet are PHP for example. Speed of development, robustness, cost of running the environment, etc... tend to be far more important when you start to scale than any theoretical speed difference.

请记住,.Net 具有原始类型、类型安全性和诸如此类的东西,这些东西将使代码比 PHP 运行速度更快.如果您想做一个有点不公平的测试,请在两个平台上对一百万个随机 64 位整数的数组进行排序.ASP.NET 会杀死它,因为它们是原始类型,并且简单数组将比 PHP 的关联数组更有效(并且 PHP 中的所有数组最终都是关联的).此外,32 位操作系统上的 PHP 不会具有本机 64 位整数,因此会因此而遭受巨大损失.

Bear in mind that .Net has primitive types, type safety and these sorts of things that will make code faster than PHP can run it. If you want to do a somewhat unfair test, sort an array of one million random 64 bit integers in both platforms. ASP.NET will kill it because they are primitive types and simple arrays will be more efficient than PHP's associative arrays (and all arrays in PHP are associative ultimately). Plus PHP on a 32 bit OS won't have a native 64 bit integer so will suffer hugely for that.

还应该指出的是,ASP.NET 是预编译的,而 PHP 是即时解释的(不包括操作码缓存),这可能会有所不同,但 PHP 在这方面的灵活性是一件好事.能够在不弹跳服务器的情况下部署脚本很棒.只需将其放入即可.杰出的.但它最终的性能较差.

It should also be pointed out that ASP.NET is pre-compiled whereas PHP is interpreted on-the-fly (excluding opcode caching), which can make a difference but the flexibility of PHP in this regard is a good thing. Being able to deploy a script without bouncing your server is great. Just drop it in and it works. Brilliant. But it is less performant ultimately.

最终,尽管我认为您在争论什么是真正不相关的细节.

Ultimately though I think you're arguing what's really an irrelevant detail.

这篇关于代码执行速度:ASP.NET-MVC 与 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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