欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

javascript 字符串连接的性能问题(多浏览器)_javascript技巧

程序员文章站 2022-05-11 11:31:43
...
书中附带的测试代码如下
复制代码 代码如下:



Example


Note: The latest versions of Firefox seem to have fixed the string concatenation problem. If you are using Firefox 1.0 or later, the string buffer may actually take longer than normal string concatenation.








在 Firefox/3.0.3中执行的结果如下:
Concatenation with plus: 5 milliseconds
Concatenation with StringBuffer: 10 milliseconds
在IE6中执行结果如下:
Concatenation with plus: 234 milliseconds
Concatenation with StringBuffer: 62 milliseconds
1.两种方式性能差别很大
2.看来IE6字符串连接处理能力比FF3很差呀
3.IE6和FF3两种方式结果相反,看来以后写连接优化还有注意浏览器呀