字符串连接性能测试
编辑:dnawo 日期:2008-01-31
先看一个例子:
测试结果:
Test1平均使用时间:0.594毫秒
Test2平均使用时间:0.125毫秒
Test3平均使用时间:0.016毫秒
不用再说什么了,从结果中我们已经能清楚的知道哪种性能最好了,呵呵。
参考文章:
1.VBscript 字符串串接的优化技巧:http://bbs.dvbbs.net/dispbbs.asp?boardID=148&ID=1445441
2.关于vbs的字符串操作效率分析总结:http://bbs.dvbbs.net/dispbbs.asp?boardid=1&Id=1479595
复制内容到剪贴板
程序代码

<%
Dim StartTime,EndTime,i
Dim Temp,Arr(4999)
Const a1="aaaaaa"
Const a2="bbbbbb"
Const a3="cccccc"
StartTime = Timer()
'逐个打开测试
'Response.Write(Test1())
'Response.Write(Test2())
'Response.Write(Test3())
EndTime = Timer()
Response.Write("使用时间:" & FormatNumber((EndTime-StartTime),3) & "毫秒")
Function Test1()
For i=0 to 4999
Temp = Temp & a1 & a2 & a3
Next
Test1 = Temp
End Function
Function Test2()
For i=0 to 4999
Temp = Temp & (a1 & a2 & a3)
Next
Test2 = Temp
End Function
Function Test3()
For i=0 to 4999
Arr(i) = a1 & a2 & a3
Next
Test3 = Join(Arr,"")
End Function
%>
Dim StartTime,EndTime,i
Dim Temp,Arr(4999)
Const a1="aaaaaa"
Const a2="bbbbbb"
Const a3="cccccc"
StartTime = Timer()
'逐个打开测试
'Response.Write(Test1())
'Response.Write(Test2())
'Response.Write(Test3())
EndTime = Timer()
Response.Write("使用时间:" & FormatNumber((EndTime-StartTime),3) & "毫秒")
Function Test1()
For i=0 to 4999
Temp = Temp & a1 & a2 & a3
Next
Test1 = Temp
End Function
Function Test2()
For i=0 to 4999
Temp = Temp & (a1 & a2 & a3)
Next
Test2 = Temp
End Function
Function Test3()
For i=0 to 4999
Arr(i) = a1 & a2 & a3
Next
Test3 = Join(Arr,"")
End Function
%>
测试结果:
Test1平均使用时间:0.594毫秒
Test2平均使用时间:0.125毫秒
Test3平均使用时间:0.016毫秒
不用再说什么了,从结果中我们已经能清楚的知道哪种性能最好了,呵呵。
参考文章:
1.VBscript 字符串串接的优化技巧:http://bbs.dvbbs.net/dispbbs.asp?boardID=148&ID=1445441
2.关于vbs的字符串操作效率分析总结:http://bbs.dvbbs.net/dispbbs.asp?boardid=1&Id=1479595






评论: 2 | 引用: 0 | 查看次数: 4309





是配置的原因吧
沙发
使用时间:2.438毫秒
使用时间:0.750毫秒
使用时间:0.016毫秒
我测试的跟你不一样,是不是电脑的配置不同哦
使用时间:0.750毫秒
使用时间:0.016毫秒
我测试的跟你不一样,是不是电脑的配置不同哦
发表评论
请登录后再发表评论!