Javascript中的字符串连接与字符串缓冲区 [英] String concatenation vs string buffers in Javascript

查看:94
本文介绍了Javascript中的字符串连接与字符串缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读本书 - 用于Web开发人员的专业Javascript,与使用数组存储字符串然后使用join方法创建最终字符串相比,作者提到字符串连接是一项昂贵的操作。好奇,我在这里做了几个测试,看看它会节省多少时间,这就是我得到的 -

I was reading this book - Professional Javascript for Web Developers where the author mentions string concatenation is an expensive operation compared to using an array to store strings and then using the join method to create the final string. Curious, I did a couple test here to see how much time it would save and this is what I got -

http://jsbin.com/ivako

不知何故,Firefox通常会产生两种相似的时间,但在IE中,字符串连接要快得多。那么,这个想法现在可以被认为是过时的(浏览器可能已经改进了吗?

Somehow, the Firefox usually produces somewhat similar times to both ways, but in IE, string concatenation is much much faster. So, can this idea now be considered outdated (browsers probably have improved since?

推荐答案

**编辑:我认为人们还在查看这篇文章 - 但已经3年多了,所以只关注以下内容符合您的最佳利益: http ://jsperf.com/string-concatenation/14

** I assume people are still viewing this post--but it has been 3+ years, so it is in your best interest to just view: http://jsperf.com/string-concatenation/14

查看此帖子的更改,了解它的用途。

View the changes of this post to see what it used to say.

这篇关于Javascript中的字符串连接与字符串缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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