有没有比较 PHP 和 JSP 的基准?

发布于 2024-08-11 15:57:38 字数 49 浏览 2 评论 0原文

我不想发动圣战。我只是想知道有没有这样的基准?或者你可以根据你的经验谈谈这个话题吗?

I don't want to make a holy war. I just want to know if there is such benchmark? Or maybe you can say something about this thread from your experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴情换悲伤 2024-08-18 15:57:38

我只是偶然发现了这种语言

事实上,像 PHP 这样的解释语言总是比编译语言慢。 JSP 文件也会被编译,因此一旦服务器开始运行并且不再更改,性能将比每次请求进入时都会解释的 PHP 脚本更好。

另一方面,第一个性能无论如何,您遇到的瓶颈可能是数据库速度。还有很多其他方法可以提高性能,例如预编译 PHP 脚本、将繁重的计算外部化为 C 等。与 Java Web 开发的庞然大物相比,PHP 很容易学习和相处。最后,如果可以选择,您应该选择您最熟悉的语言。如果您正在开始一个新项目,您甚至可能不知道所有性能考虑因素是否都重要,因为您还没有用户,只想快速推出您的应用程序。

I just stumbled over the language shootout yesterday, again where you can compare some performance characteristics of both languages while running different programs. I didn't find a benchmark for web performance, though.

Fact is, that interpreted languages like PHP are always slower than a compiled language. JSP files get compiled, too, so once the server is up an running and doesn't get changed anymore, the performance will be better than a PHP script that gets interpreted every time a request comes in.

On the other hand, the first performance bottleneck you will have will probably be the database speed, anyway. And then there are still lots of other ways for improving performance like pre compiling your PHP scripts, externalizing heavy calculations into C etc. And compared to the monster of Java web development PHP is easy to learn and to get along with. In the end, if you have the choice, you should go with the language you are most comfortable with. If you are starting a new project you may not even know if all the performance considerations will ever be important because you don't have the users yet and just want to get your application out there quickly.

下壹個目標 2024-08-18 15:57:38

虽然 Daff 对 PHP 与 JSP 的解释在技术上是错误的,但他的帖子的基本要点是正确的:选择最适合您的语言。只有极少数情况下,您才会发现自己处于绩效非常重要的境地。那时,您更有可能能够使用您选择的语言进行重大的架构优化 - 并且这些优化可能比 PHP 和 JSP 之间的差异具有更大的效果。

编程的核心规则之一始终是避免过早优化 - 如果没有其他原因,只是因为直到你真正处于压力之下时,你才知道你真正需要优化什么,也没有办法确定是否需要优化它起作用了。

如果您认为自己可能会遇到性能问题,则没有任何网站可以帮助您。最重要的是创建您自己的负载测试基准,该基准代表您的网站如何工作的细节,模拟您的用户如何做事。只有完成此操作后,您才能继续调整代码,实现缓存、负载平衡、数据和请求分区等内容,并确信您所做的更改会对站点性能产生积极影响。

有一些书籍专门介绍一般优化过程,但关键顺序是这样的:

  1. 基准
  2. 更改测试
  3. 基准以查看更改是否表明性能改进
  4. 上线
  5. 评估实时响应以查看基准预测是否正确

(人们经常忘记#5,并给自己带来悲伤)

如果您要花时间担心性能,请花时间设置该顺序,不要花时间担心您的语言选择。

While Daff's explanation of PHP vs JSP is technically wrong, the essential gist of his post is correct: choose the language that is best for you. Only very rarely will you find yourself in a position where performance really matters badly. At that point, you are much more likely to be able to make significant architectural optimizations in your language of choice - and these optimizations are likely to have significantly more effect than the difference between PHP and JSP.

One of the core rules of programming has always been to avoid premature optimization - if for no other reason than because until you're actually under pressure you don't know what you actually need to optimize, nor do you have a means of determining whether it worked.

In the event that you believe there's a possibility you may face performance issues, no website can help you. The most vital thing is to create your own load testing benchmarks that represent the specifics of how your site works, simulating how your users do things. Only once you have done that are you able to move on to tweaking your code, implementing things like caching, load balancing, data and request partitioning etc with any confidence that the changes you are making are having a positive impact on your site performance.

There are books specifically about the process of optimization in general, but the key sequence is this:

  1. Benchmark
  2. Change test
  3. Benchmark to see if change indicates performance improvement
  4. Go live
  5. Evaluate live response to see if benchmark prediction was correct

(People forget #5 a lot and cause themselves grief)

If you're going to spend time worrying about performance, spend time setting up that sequence, don't spend time worrying about your language choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文