也就是说,如果我需要为单个数组插入调用这个函数,我是否更适合使用某种树或跳过列表数据结构?
That is, would I be better suited to use some kind of tree or skip list data structure if I need to be calling this function a lot for individual array insertions?
推荐答案您可以考虑是否要使用对象;所有JavaScript对象(包括 Array 实例)是具有可选原型的(高度优化的)键/值对集合实现应该(注意我不要说确实)具有合理的性能哈希算法。 (更新:那是在2010年。在2018年,对象在所有重要的JavaScript引擎上进行了高度优化。)
You might consider whether you want to use an object instead; all JavaScript objects (including Array instances) are (highly-optimized) sets of key/value pairs with an optional prototype An implementation should (note I don't say "does") have a reasonable performance hashing algorithm. (Update: That was in 2010. Here in 2018, objects are highly optimized on all significant JavaScript engines.)
除此之外, splice 的性能将在实现(例如,供应商)之间变化 lot 。这就是为什么不过早优化对于将在多个供应商实现(例如,网络应用程序)中运行的JavaScript应用程序而言甚至比正常编程更合适的一个原因。保持您的代码模块化,并在发生时解决性能问题。
Aside from that, the performance of splice is going to vary a lot between implementations (e.g., vendors). This is one reason why "don't optimize prematurely" is even more appropriate advice for JavaScript applications that will run in multiple vendor implementations (web apps, for instance) than it is even for normal programming. Keep your code well modularized and address performance issues if and when they occur.
更多推荐
Javascript:'拼接'的算法性能是什么?
发布评论