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.Writesn & " " & 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.Writesn & " " & 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.Writesn & " " & 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.Writesn & " " & 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.Writesn & " " & tou * 24 * 60 * 60 & " <br>"
91 next
92
93 % >
94 用FOR循环比DOWHILE循环要快得多,用下面的程序测试,虽然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.Writesn & " " & 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.Writesn & " " & 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.Writesn & " " & 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.Writesn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
148 next
149
150
151 % >
152
153
154 这段程序从SN=3起就很慢,而前面非常快
155 < ! -- #includefile = " 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名称fromuserwhere名称='阿余'"
162 Set rs = Server. CreateObject ( " ADODB.RecordSet " )
163 rs.Opensql,conn, 1 , 3
164 rs( " 名称 " ) = " 阿余"
165 rs.update
166 rs.close
167 next
168 ttt2 = now ()
169 tou = ttt2 - ttt1
170 Response.Writesn & " " & tou * 24 * 60 * 60 & " : " & session( " s " & i - 1 ) & " <br>"
171 next
172
173
174 % >
175
176
177 而这样就快多了。看来建对象很要花些时间,还有,用MOVE 0 , 1 和MOVEFIRST相比速度没有什么差别。
178 < ! -- #includefile = " filetou.asp " -->
179 < %
180 sql = " SELECT名称fromuserwhere名称='阿余'"</s
分享到:
评论

你可能感兴趣的:(sql,C++,c,server,C#,asp)