关于在IE和FireFox下ASP.NET AJAX框架的StringBuilder对象效率的测试 [ZT]
1. 直接使用 += 运算符的循环5万次:
循环用时IE下32S,FireFox下2S
2.使用StringBuilder:
var sbTest=new Sys.StringBuilder();
for(var i=0;i<50000;i++)
{
var now=new Date();
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
sbTest.append(now.getSeconds());
}
$get("message").innerHTML=sbTest.toString('|<br/>');
测试结果如下:
50W次IE下6S,FireFox下3S
结果相差竟然如此之大。IE下显然是用StringBuilder的效率要高于+=的效率,可是在FireFox下无论使用StringBuilder还是不使用之均无较大的差别。
1
var sbTest//=new Sys.StringBuilder();
2
for(var i=0;i<50000;i++)
3
{
4
var now=new Date();
5
sbTest += now.getSeconds() + "<br/>";
6
}
7
8
$get("message").innerHTML=sbTest;//.toString('|<br/>');
测试结果如下:![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
循环用时IE下32S,FireFox下2S
2.使用StringBuilder:
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://hanxianlong.cnblogs.com/Images/OutliningIndicators/None.gif)
测试结果如下:
50W次IE下6S,FireFox下3S
结果相差竟然如此之大。IE下显然是用StringBuilder的效率要高于+=的效率,可是在FireFox下无论使用StringBuilder还是不使用之均无较大的差别。