在哪里对集合进行排序会更快 - 客户端还是服务器端?

发布于 2024-12-27 19:48:34 字数 424 浏览 2 评论 0原文

我有一个关于客户端与服务器端处理的问题。

我有一个相当大的对象集合(假设是一个由日常字段组成的“用户”对象集合 - namelast nameageisAdmin 等...)

现在,我想将这个大集合分成两个小集合,其中谓词是一个布尔字段 - isAdmin - 它告诉我们是否用户是否是管理员。

分离后,我需要将两个最终集合发送到服务器端进行一些更复杂的处理。

我想知道在客户端进行排序和拆分会更有效(也许使用 Javascript 或 jQuery?它会起作用吗?)或者只是将大集合发送到服务器并让它处理所有内容(都拆分)使用 LINQ 和进一步处理)。

一般来说,在什么情况下使用客户端比使用服务器端更好?为什么?

I have a question concerning client side vs. server side processing.

I have a rather big collection of objects (lets say a collection of "user" objects which consists of everyday fields - name, last name, age, isAdmin etc...)

Now, I want to separate this big collection into two small collections where the predicate is a boolean field - isAdmin - which tells us if the user is an admin or not.

After the separation I will need to send both final collections to the server side for some more complex processing.

I was wondering where it will be more efficient to do the sorting and spliting in the client side (using Javascript or jQuery perhaps? would it do the trick?) or just send the big collection to the server and let it handle everything (both splitting using LINQ and further processing).

And generally, in which cases is it better to use client side over server side? and why?

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

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

发布评论

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

评论(2

再可℃爱ぅ一点好了 2025-01-03 19:48:34

与往常一样,性能问题通常很难回答,因此它取决于:

  • 数据集的大小(“相当大的集合”是指 100 个还是 1000000 个?)
  • 客户端和服务器端硬件
  • 网络延迟和传输速度...

你确实需要做一些测试才能解决这个问题。即便如此,由于每个用户都可能使用不同的计算机,因此对于我来说,2001 年老式硬件上的答案可能与使用 2011 年四核(16GB 内存和最高效的 JavaScript 解释器)的人不同。

As always, performance questions are hard to answer in general, so it depends on:

  • the size of your dataset (does "rather big collection" mean 100's or 1000000's ?)
  • the client-side and server-side hardware
  • the network latency and transmission speed ...

You'd really have to do some testing to figure this one out. Even then, because every user could be on a different computer, the answer might be different for me on my 2001-vintage hardware compared to somebody with a 2011 quad-core with 16GB of memory and the most efficient javascript interpreter.

三生池水覆流年 2025-01-03 19:48:34

这个问题确实没有简单的答案,因为有很多变量在起作用,例如:

  • 计算能力
  • 计算工作量
  • 各种语言的排序算法实现(记住,jQuery不是

……可能还有很多其他东西。

过去我们可以说服务器总是比客户端更快,但由于强大计算的高可用性和应用程序托管的商品化,这种情况不再一定是这样了。

但除了速度之外,还有其他事情需要考虑,比如安全性。如果您的 User 对象包含敏感信息,您真的希望信任客户端计算机拥有该数据吗?

There is really no simple answer to this, as there are a lot of variables at play such as:

  • Computing power
  • Computing workload
  • Sorting algorithm implementations in various languages (please remember that jQuery is not a language)

... and probably a bunch of other things.

It used to be the case that we could say that the server was always faster than the client, but that isn't necessarily true anymore because of the high availability of powerful computing and the commoditization of application hosting.

But besides speed, there are other things to consider, such as security. If your User object contains sensitive information, do you really want to trust a client's computer with that data?

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