Java在处理数据结构方面是否比JavaScript更高效?

huangapple go评论76阅读模式
英文:

Is Java much more efficient than JavaScript when it comes to working with data structures?

问题

我使用Javascript + React开发了一个Web应用,并使用Java作为后端创建了一个REST API。前端通过REST从后端接收一个类似于以下结构的对象列表:

{
  "id": "11111",
  "operationDate": "2020-02-21 00:00:00",
  "status": "A"
  ...
}

这些对象按id分组(在这种情况下不是唯一的),然后按日期排序(在组内排序)。这已经在JavaScript中完成了,但我想知道是否应该将分组和排序移到Java中,并通过REST发送已经分组和排序的数据以提高性能。这将需要一些工作,所以我想知道是否值得这样做。

英文:

I develop a web app with Javascript + React and a REST API in Java as backend.
The frontend receives from backend via REST a list of objects which look like this:

{
  "id": "11111",
  "operationDate": "2020-02-21 00:00:00",
  "status": "A"
  ...
}

Those objects are grouped by id (which is not unique in this case) and then sorted (within a group) by date. It's already done in JavaScript, but I wonder if I should move grouping and sorting to Java and send it via REST already grouped and sorted for the sake of performance. It will require some work so I'd like to know if it's worthwhile.

答案1

得分: 1

回答我的问题:我测量了对一组12k+对象进行分组和排序的时间,结果显示仅花费了16毫秒。考虑到将其转移到后端所需的工作量,以及传入的列表很难会更大,这是不值得的。

英文:

Answering my own question: I measured the time of the grouping and sorting for a set of 12k+ objects and it appears it took only 16 miliseconds. Considering the amount of work necessary to move it to backend and fact that incoming lists will hardly ever be larger it's not worth it.

huangapple
  • 本文由 发表于 2020年9月23日 18:34:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/64026048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定