String concatenation vs string buffers in Javascript

后端 未结 7 1926
清酒与你
清酒与你 2020-12-24 14:24

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 s

相关标签:
7条回答
  • 2020-12-24 14:59

    As we know, not all browsers are created equal. Because of this, performance in different areas is guaranteed to differ from browser to browser.

    That aside, I noticed the same results as you did; however, after removing the unnecessary buffer class, and just using an array directly and a 10000 character string, the results were even tighter/consistent (in FF 3.0.12): http://jsbin.com/ehalu/

    Unless you're doing a great deal of string concatenation, I would say that this type of optimization is a micro-optimization. Your time might be better spent limiting DOM reflows and queries (generally the use of document.getElementbyById/getElementByTagName), implementing caching of AJAX results (where applicable), and exploiting event bubbling (there's a link somewhere, I just can't find it now).

    0 讨论(0)
提交回复
热议问题