Javascript:'拼接'的算法性能是什么?

编程入门 行业动态 更新时间:2024-10-18 21:19:32
本文介绍了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:'拼接'的算法性能是什么?

本文发布于:2023-11-29 03:57:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   性能   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!