jQuery vs.PHP-性能比较 [英] jQuery vs. PHP - Performance Comparison

查看:88
本文介绍了jQuery vs.PHP-性能比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在性能方面,哪个是更好的解决方案?这是一个非常小的例子. PHP脚本将一个数字返回给jQuery,需要检查它是否为1,页面需要显示"1 person",否则为"X person".

Performance-wise, which would be the better solution? Here's a really small example. The PHP script returns a number to jQuery, which needs to be checked if it's 1, the page needs to say "1 person", else "X persons".

PHP脚本执行此检查并返回"x人",或者jQuery在获得数字后执行此操作,会更快吗?

Would it be faster for the PHP script to make this check and return "x persons", or for jQuery to do it after getting the number?

推荐答案

我假设您要进行的案件有所不同,这只是一个示例-过于简化.支票很小,所以我怀疑您可以衡量差异,但是可以说您有很多支票.

I'm assuming you have a different case going on, and this is just an example -overly simplified-. The check is a very small one, so I doubt you can measure difference, but lets say you have LOTS of these checks.

正如@mkoryak所说,jQuery是客户端,PHP是服务器端.如果10 ^ 5个用户要求这样做,则让jQuery执行此操作时您可能会看到一些区别:每个人都做一次(并且看不到区别),但是您的服务器却少做10 ^ 5个检查.反之,您的服务器可能比客户端要快得多,因此对于一个客户端(有几个客户端,甚至只有一个客户端),很多计算可能会更好地在服务器上运行(因此,PHP是您的选择).

As @mkoryak says, jQuery is clientside and PHP is serverside. If 10^5 users are requesting this, you might see some difference when letting jQuery do this: everyone does it once (and doesn't see the difference), but your server gets to do 10^5 checks less. The other way around, your server is probably a lot quicker then your client, so a lot of calculations for 1 client (with few, or even a single client) might be better run on the server (so PHP would be your choice).

@slebetman总结:对于少量客户端,服务器端代码通常更快.对于大量客户端,将工作卸载到客户端代码可以极大地提高性能.这就是@scunliffe答案的来源:用压力测试测试您的解决方案!

As @slebetman concludes: For small number of clients, server side code is generally faster. For very large number of clients, offloading work to client side code can greatly improve performance. Here is where @scunliffe 's answer comes in: test your sollution with a stresstest!

这篇关于jQuery vs.PHP-性能比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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