仿Java类StringBuffer类性能测试


StringBuffer = function(){
this.arr = new Array();
this.appendChild = function(str){
this.arr.push(str);
}

this.toString = function(){
return this.arr.join("");
}
}

for(var k=1;k<=20;k++){
document.write("NO."+k+"<br>")
var sb = new StringBuffer();
var startDate = new Date();
for(var i=0;i<10000;i++){
sb.appendChild("I");
}
sb.toString();
var endDate = new Date();

document.write(" Use first method:"+(endDate.getTime()-startDate.getTime())+" (milliseconds)<br>");

var str = "";
var startDate2 = new Date();
for(var i=0;i<10000;i++){
str+="I"
}
var endDate2 = new Date();
document.write(" Use second method:"+(endDate2.getTime()-startDate2.getTime())+" (milliseconds)<br>");
}



[quote]
[size=large]Result:[/size]


NO.1
Use first method:47 (milliseconds)
Use second method:313 (milliseconds)
NO.2
Use first method:62 (milliseconds)
Use second method:266 (milliseconds)
NO.3
Use first method:62 (milliseconds)
Use second method:297 (milliseconds)
NO.4
Use first method:47 (milliseconds)
Use second method:297 (milliseconds)
NO.5
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.6
Use first method:47 (milliseconds)
Use second method:297 (milliseconds)
NO.7
Use first method:47 (milliseconds)
Use second method:312 (milliseconds)
NO.8
Use first method:47 (milliseconds)
Use second method:313 (milliseconds)
NO.9
Use first method:47 (milliseconds)
Use second method:312 (milliseconds)
NO.10
Use first method:47 (milliseconds)
Use second method:313 (milliseconds)
NO.11
Use first method:46 (milliseconds)
Use second method:313 (milliseconds)
NO.12
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.13
Use first method:46 (milliseconds)
Use second method:313 (milliseconds)
NO.14
Use first method:47 (milliseconds)
Use second method:328 (milliseconds)
NO.15
Use first method:47 (milliseconds)
Use second method:312 (milliseconds)
NO.16
Use first method:47 (milliseconds)
Use second method:328 (milliseconds)
NO.17
Use first method:47 (milliseconds)
Use second method:297 (milliseconds)
NO.18
Use first method:63 (milliseconds)
Use second method:328 (milliseconds)
NO.19
Use first method:47 (milliseconds)
Use second method:343 (milliseconds)
NO.20
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.21
Use first method:47 (milliseconds)
Use second method:312 (milliseconds)
NO.22
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.23
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.24
Use first method:46 (milliseconds)
Use second method:344 (milliseconds)
NO.25
Use first method:47 (milliseconds)
Use second method:328 (milliseconds)
NO.26
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.27
Use first method:47 (milliseconds)
Use second method:343 (milliseconds)
NO.28
Use first method:63 (milliseconds)
Use second method:328 (milliseconds)
NO.29
Use first method:47 (milliseconds)
Use second method:328 (milliseconds)
NO.30
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.31
Use first method:47 (milliseconds)
Use second method:328 (milliseconds)
NO.32
Use first method:47 (milliseconds)
Use second method:375 (milliseconds)
NO.33
Use first method:46 (milliseconds)
Use second method:344 (milliseconds)
NO.34
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.35
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.36
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.37
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.38
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.39
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.40
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.41
Use first method:47 (milliseconds)
Use second method:344 (milliseconds)
NO.42
Use first method:47 (milliseconds)
Use second method:343 (milliseconds)
NO.43
Use first method:47 (milliseconds)
Use second method:360 (milliseconds)
NO.44
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.45
Use first method:62 (milliseconds)
Use second method:344 (milliseconds)
NO.46
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.47
Use first method:47 (milliseconds)
Use second method:360 (milliseconds)
NO.48
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.49
Use first method:47 (milliseconds)
Use second method:359 (milliseconds)
NO.50
Use first method:47 (milliseconds)
Use second method:375 (milliseconds)

[color=red]Memory:2G
CPU: Inter(R) Pentium(R) Dual Cpu E2200 @2.2GHz[/color]
[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值