PHP与JavaScript的速度? [英] Speed of PHP vs JavaScript?

查看:118
本文介绍了PHP与JavaScript的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来标记文件内容。我用JavaScript编写了一个tokenizer,但是对于大文件(5秒以上)来说它变得非常慢。因为我正在从服务器检索文件,我正在考虑用PHP重写它以减少几秒钟。我已经读过PHP和JavaScript之间的速度差异可以忽略不计,但是如果文件是1mb或更大,则速度差异可能会增加。我在网上找到了这个基准,但我不确定这些信息是否是最新的(所有信息都是最新的)过去几年的JS引擎优化)。

I am writing a script to tokenize file contents. I've written a tokenizer in JavaScript, but it gets pretty slow with large files (5+ seconds). Since I'm retrieving the files from the server anyways, I am considering rewriting it in PHP to shave off a few seconds. I've read that the speed difference between PHP and JavaScript is negligible, but if the files are 1mb or bigger, a small speed difference could add up. I found this benchmark online, but I'm not sure if the info is up-to-date (with all the JS engine optimizations from the past couple years).

移植我的所有代码需要一些工作,所以如果我能帮助它,我就不会使用PHP。但如果它会更快(25-30%),那就值得。

Porting over all my code would take some work, so if I can help it, I won't use PHP. But if its going to be much faster (25-30%), it would be worth it.

推荐答案

好吧,和你一样提到,JavaScript在客户端执行,因此它取决于客户端。例如,iPAD上的客户端将无法像在游戏机上运行的客户端那样顺畅地运行这些Quake3 HTML5。另一方面,PHP在服务器上运行。

Well, like you alluded, JavaScript is executed on the client side, so it would depend on the client. For example, a client on an iPAD wouldn't be able to run those Quake3 HTML5s as smoothly as a client running on a gaming machine. PHP on the other hand runs on the server.

一般来说,JS比PHP更快(在同一硬件上);

In general, JS is faster considerably than PHP though (on the same hardware);

以下是两者之间的一些[硬数据] [1]测试,以支持我的断言。
[JS(查询)vs PHP] [2]性能。

Here are some [hard figures][1] of tests between the two, to back up my assertion. [JS (query) vs PHP][2] Performance.

[1]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/php-node.html [ 2]: jQuery与PHP - 性能比较

[1]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/php-node.html [2]: jQuery vs. PHP - Performance Comparison

这篇关于PHP与JavaScript的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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