提高js字符串连接的性能
来源:互联网 发布:icq聊天软件 编辑:程序博客网 时间:2024/06/05 06:49
转贴来自:http://hi.baidu.com/x8online/blog/item/5a3e20d3d1814d013bf3cfce.html
方法:定义一个StringBuffer类,在定义个方法(模拟C#中StringBuilder类)与直接使用连接字符相比
<script type="text/javascript">
function StringBuffer()//使用构造函数
{
this._strings_=new Array;
}
StringBuffer.prototype.append=function (str)//使用原型定义函数属性
{
this._strings_.push(str);
}
StringBuffer.prototype.toString=function ()//使用原型定义函数属性
{
return this._strings_.join("");
}
var buffer=new StringBuffer();//使用类
d1=new Date();
for(var i=0;i<10000;i++)
{
buffer.append("text");
}
var result=buffer.toString();
d2=new Date();
document.write ("<br>Concatenation with StringBuffer:"+(d2.getTime()-d1.getTime())+"milliseconds<br>");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var d1=new Date();
var str="";
for(var i=0;i<10000;i++)
{
str+="text";
}
var d2=new Date();
document.write ("<br>Concatenation with StringBuffer:"+(d2.getTime()-d1.getTime())+"milliseconds");
</script>
结果:Concatenation with StringBuffer:110milliseconds
Concatenation with StringBuffer:2422milliseconds
以上结果经测试正确,结果StringBuffer比直接使用连接字符节省100%~200%的时间
- 提高js字符串连接的性能
- 提高字符串连接的效率
- 连接字符串连接的性能
- 连接模式:提高数据库性能的捷径
- javascript字符串连接的性能
- 当心字符串连接的性能
- js 性能提高 (转载)
- Js中字符串的连接
- js中字符串的连接
- JS高性能字符串连接StringBuffer类[转]
- JS中三种字符串连接方式及其性能比较
- JS中三种字符串连接方式及其性能比较
- 从一道编程题看JS字符串连接性能
- JS中三种字符串连接方式及其性能比较
- 提高abap数据访问性能的几篇文章的连接
- 提高abap数据访问性能的几篇文章的连接
- 提高abap数据访问性能的几篇文章的连接
- 字符串连接的性能(Effective java)- -
- FreeBSD + Lighttpd + Django + FastCGI
- EXcel分类显示法
- Oracle并行服务器(OPS)
- 简单说两句 Like 的优化
- 10步完成freebsd下 python+django+fastcgi+lighttpd+sqlite3 源码安装与配置.
- 提高js字符串连接的性能
- fast report 的使用说明
- Visual Studio 2008之新特性LINQ(三)之LINQ To Object查询
- iReport 笔记(一) 序
- 网站变黑(哀悼!!!!)
- 一位软件工程师的6年总结
- Unit Testing (using ReSharper 3.1)
- (转)form和column:extJS的布局
- sql问题小结