[Miles' Blog]

Welcome 2 My Planet

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

The performance of predefined objects in ASP|ASP内置对象的性能 [Permalink]

Fri Mar 17 16:06:49 CST 2006
Category [development. ~]

代码片断一:

<%
Dim localArray(5000)
for i = 0 to ubound(localArray)
  randomize
  localArray(i) = rnd()*1000
next

application("tester") = localArray

start = timer
for i = 0 to ubound(application("tester"))
  if application("tester")(i) > 800 then
    application("tester")(i) = 800
  end if
  if application("tester")(i) > 700 then
    application("tester")(i) = 700
  end if
  if application("tester")(i) > 600 then
    application("tester")(i) = 600
  end if
  if application("tester")(i) > 500 then
    application("tester")(i) = 500
  end if
next

response.write formatnumber((timer - start), 2, -1)
%>


代码片断二:
<%
Dim localArray(5000), localArray2
for i = 0 to ubound(localArray)
  randomize
  localArray(i) = rnd()*1000
next

application("tester") = localArray

start = timer
localArray2 = application("tester")

for i = 0 to ubound(localArray2)
  if localArray2(i) > 800 then
    localArray2(i) = 800
  end if
  if localArray2(i) > 700 then
    localArray2(i) = 700
  end if
  if localArray2(i) > 600 then
    localArray2(i) = 600
  end if
  if localArray2(i) > 500 then
    localArray2(i) = 500
  end if
next

response.write formatnumber((timer - start), 2, -1)
%>

猜猜看这两段代码性能差别会有多大?

至少从代码结构上看相差不大。第一段使用application存储数组并直接通过application来使用它;第二段则是将application中存储的数组拿出来做循环。前者应该是过集合方式取得内容,然后拿出来用,所以多了一个遍历集合和方法调用返回的过程。

可是实际每段代码执行3次时间如下:
第一段:9.14s 9.19s 9.91s
第一段:0.03s 0.03s 0.03s
不过5000次循环,可差距远比想象中大得多!而且随着循环次数增加,性能会急剧下降。1000次循环时候第一段不过是0.4s而已,5倍的循环次数就用了20多倍的时间。亲娘咧,真费解啊~~~

原因有时间再探查,结果算是记住了。。。估计request/session也好不到哪里去。

Posted by: miles
Comments [0] |

?
十二月 2018
Sun? Mon? Tue? Wed? Thu? Fri? Sat?
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
<  Nov???Today??? Jan  >
<< <   1   > >>

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

Powered By blojsom?? RSS Feed? RSS2 Feed? RDF Feed

html hits:?39867