ASP程序运行速度测试

  1 程序运行速度试验结果:
  2 1 。作相同的分支条件判断: IF   比  SELECT慢。
  3 用以下程序测试:
  4 < %
  5 dim  tttt1,ttt2
  6 session( " ii " ) = 0
  7 for  sn = 0   to   5
  8 ttt1 = now ()
  9 for  i = 0   to   300000
 10     if  session( " ii " ) = 0   then
 11       session( " ii " ) = 1
 12     else
 13       if  session( " ii " ) = 1   then
 14       session( " ii " ) = 2
 15       else
 16         if  session( " ii " ) = 2   then
 17           session( " ii " ) = 3
 18          else
 19            session( " ii " ) = 0
 20           end   if
 21       end   if
 22     end   if
 23 next
 24 ttt2 = now ()
 25 tou = ttt2 - ttt1
 26 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
 27 next
 28
 29 for  sn = 0   to   5
 30 ttt1 = now ()
 31 for  i = 0   to   300000
 32     select   case  session( " ii " )
 33        case   0
 34          session( " ii " ) = 1
 35        case   1
 36          session( " ii " ) = 2
 37         case   2
 38          session( " ii " ) = 3
 39         case   3
 40          session( " ii " ) = 0
 41     end   select
 42 next
 43 ttt2 = now ()
 44 tou = ttt2 - ttt1
 45 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
 46 next
 47
 48 % >
 49 2 , 如果把上例中的SESSION对象改为用普通的变量存。速度会快差不多8倍
 50 3 ,进行字符串连接时往中间加入相同多的字符串,基数越大,越慢。
 51 通过下面的程序测试:
 52 < %
 53 dim  tttt1,ttt2
 54 session( " ii " ) = 0
 55 for  sn = 0   to   5
 56 ttt1 = now ()
 57 '   txt=""
 58     for  i = 0   to   10000
 59        txt = " a " & txt
 60     next
 61 ttt2 = now ()
 62 tou = ttt2 - ttt1
 63 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
 64 next
 65 % >
 66 进行同样长字节的字符连接时,汉字比英文快4倍,通过下面的程序测试
 67 < %
 68
 69 dim  tttt1,ttt2
 70 for  sn = 0   to   5
 71 ttt1 = now ()
 72   txt = " "
 73     for  i = 0   to   20000
 74           txt = " " & txt
 75     next
 76 ttt2 = now ()
 77 tou = ttt2 - ttt1
 78 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
 79 next
 80
 81 txt = " "
 82 for  sn = 0   to   5
 83 ttt1 = now ()
 84   txt = " "
 85     for  i = 0   to   20000
 86           txt = " aa " & txt
 87     next
 88 ttt2 = now ()
 89 tou = ttt2 - ttt1
 90 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
 91 next
 92
 93 % >
 94 用FOR 循环比DO  WHILE循环要快得多,用下面的程序测试,虽然FOR循环中要多一个变量,
 95 < %
 96 dim  tttt1,ttt2
 97
 98 for  sn = 0   to   5
 99 ttt1 = now ()
100   i = 0
101     do   while  i <= 100000
102       i = i + 1
103     loop
104 ttt2 = now ()
105 tou = ttt2 - ttt1
106 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
107 next
108
109 for  sn = 0   to   5
110 ttt1 = now ()
111    ii = 0
112     for  i = 0   to   100000
113     ii = ii + 1
114     next
115 ttt2 = now ()
116 tou = ttt2 - ttt1
117 Response.Write sn & " " & tou * 24 * 60 * 60 & " <br>"
118 next
119 % >
120 定义5000个一个字符的SESSION并不比定义5000个有5000个字符串长的SESSION少花很多时间,两者时间差仅为近一倍,用一秒多钟。倒是生成这个5000个字符长的变量花了不少的时间, < %
121 dim  tttt1,ttt2
122 c = " a"
123 for  sn = 0   to   5
124
125 session.abandon
126 ttt1 = now ()
127     for  i = 0   to   5000
128        session( " s " & i) = c
129      next
130 ttt2 = now ()
131 tou = ttt2 - ttt1
132 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
133 next
134
135 for  i = 0   to   5000
136   c = " a " & c
137 next
138
139 for  sn = 0   to   5
140 session.abandon
141 ttt1 = now ()
142     for  i = 0   to   5000
143        session( " s " & i) = c
144      next
145 ttt2 = now ()
146 tou = ttt2 - ttt1
147 Response.Write sn & " " & tou * 24 * 60 * 60 & " : "    & session( " s " & i - 1 ) & " <br>"
148 next
149
150
151 % >
152
153
154 这段程序从SN=3起就很慢,而前面非常快
155 < ! -- #include file = " filetou.asp " -->
156 < %
157 dim  tttt1,ttt2
158 for  sn = 0   to   5
159 ttt1 = now ()
160    for  i = 1   to    20
161    sql  = " SELECT 名称  from user where 名称='阿余'"
162     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
163    rs.Open sql,conn, 1 , 3
164    rs( " 名称 " ) = " 阿余"
165    rs.update
166    rs.close
167 next
168 ttt2 = now ()
169 tou = ttt2 - ttt1
170 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
171 next
172
173
174 % >
175
176
177 而这样就快多了。看来建对象很要花些时间,还有,用MOVE  0 , 1  和  MOVEFIRST 相比速度没有什么差别。
178 < ! -- #include file = " filetou.asp " -->
179 < %
180    sql  = " SELECT 名称  from user where 名称='阿余'"
181     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
182    rs.Open sql,conn, 1 , 3
183 dim  tttt1,ttt2 
184 for  sn = 0   to   5
185 ttt1 = now ()
186    for  i = 1   to    700
187    rs( " 名称 " ) = " 阿余"
188    rs.update
189    rs.movefirst
190 next
191 ttt2 = now ()
192 tou = ttt2 - ttt1
193 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
194 next
195 % >
196
197 而这两种方式相比,后者要慢3倍,可能是后者要重新查询,但比前面的用RS建查询后又去改,改了又关,相比,要快了不知多少。
198 < ! -- #include file = " filetou.asp " -->
199 < %
200    sql  = " SELECT 名称  from user where 名称='阿余'"
201     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
202    rs.Open sql,conn, 1 , 3
203 dim  tttt1,ttt2 
204
205 for  sn = 0   to   5
206 ttt1 = now ()
207    for  i = 1   to    700
208    rs( " 名称 " ) = " 阿余"
209    rs.update
210    rs.movefirst
211 next
212 ttt2 = now ()
213 tou = ttt2 - ttt1
214 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
215 next
216
217 for  sn = 0   to   5
218 ttt1 = now ()
219    for  i = 1   to    700
220      SQL = " UPDATE user set 名称='阿余'  where 名称='阿余'"
221      conn. execute  sql, 0 , - 1
222 next
223 ttt2 = now ()
224 tou = ttt2 - ttt1
225 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
226 next
227
228 % >
229
230
231 新加一万条记录谁快?第一种方法用31秒,后者直到超时仍未完成。不得已,少掉一个0,1000条是,后者慢一半。
232 < ! -- #include file = " filetou.asp " -->
233 < %
234    sql  = " SELECT 名称  from user where id=0"
235     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
236    rs.Open sql,conn, 1 , 3
237 dim  tttt1,ttt2 
238
239 ttt1 = now ()
240    for  i = 1   to    10000
241    rs.addnew
242    rs( " 名称 " ) = " 阿余A"
243    rs.update
244 next
245 ttt2 = now ()
246 tou = ttt2 - ttt1
247 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
248
249
250 ttt1 = now ()
251    for  i = 1   to    10000
252      sql = "  INSERT INTO  user (名称) VALUES('阿余B')"
253      conn. execute  sql, 0 , - 1
254 next
255 ttt2 = now ()
256 tou = ttt2 - ttt1
257 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
258
259
260 % >
261
262 下面的程序结果说明RS新增记录较快,而删除较慢,用CONN新增慢,但删除很快。
263 运行的结果为:
264 3.00000007264316 :
265 7.99999998416752 :
266 1.99999983888119 :
267 0 :
268 后来用RS新增记录5000条,并用CONN删除这5000条, 结果为:
269 17.000000202097 :
270 1.00000023376197 :
271 程序为:
272 < ! -- #include file = " filetou.asp " -->
273 < %
274 dim  tttt1,ttt2 
275 ttt1 = now ()
276 sql  = " SELECT 名称  from user where id=0"
277     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
278    rs.Open sql,conn, 1 , 3
279    for  i = 1   to    1000
280    rs.addnew
281    rs( " 名称 " ) = " 阿余A"
282    rs.update
283 next
284 ttt2 = now ()
285 tou = ttt2 - ttt1
286 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
287
288
289 ttt1 = now ()
290    for  i = 1   to    1000
291      sql = "  INSERT INTO  user (名称) VALUES('阿余B')"
292      conn. execute  sql, 0 , - 1
293 next
294 ttt2 = now ()
295 tou = ttt2 - ttt1
296 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
297
298
299
300
301 ttt1 = now ()
302    sql  = " SELECT  名称 from user where 名称='阿余A'"
303     Set  rs = Server. CreateObject ( " ADODB.RecordSet " )                        
304    rs.Open sql,conn, 1 , 3
305 do   while   not  rs.eof
306    rs.delete
307    rs.update
308    rs.move  0 , 1
309    loop
310 ttt2 = now ()
311 tou = ttt2 - ttt1
312 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
313
314
315 ttt1 = now ()
316    sql  = " delete from user  where 名称='阿余B'"
317     conn. execute  sql, 0 , - 1
318 ttt2 = now ()
319 tou = ttt2 - ttt1
320 Response.Write sn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
321 % >  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值