Javascript:'拼接'的算法性能是什么? [英] Javascript: What's the algorithmic performance of 'splice'?

查看:82
本文介绍了Javascript:'拼接'的算法性能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也就是说,如果我需要为单个数组插入调用这个函数,我是否更适合使用某种树或跳过列表数据结构?

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:'拼接'的算法性能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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