Test of running speed of several statements in ASP

Source: Internet
Author: User
Tags include insert variable
Speed | Statement program running SPEED test results:
1. The same branching condition is judged: IF is slower than select.
Test with the following program:
<%
Dim tttt1,ttt2
Session ("II") =0
For Sn=0 to 5
Ttt1=now ()
For I=0 to 300000
If session ("II") =0 Then
Session ("II") =1
Else
If session ("II") =1 Then
Session ("II") =2
Else
If session ("II") =2 Then
Session ("II") =3
Else
Session ("II") =0
End If
End If
End If
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next

For Sn=0 to 5
Ttt1=now ()
For I=0 to 300000
Select Case session ("II")
Case 0
Session ("II") =1
Case 1
Session ("II") =2
Case 2
Session ("II") =3
Case 3
Session ("II") =0
End Select
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next

%>
2, if you change the session object in the previous example to a normal variable. It's going to be almost 8 times times faster.
3, when the string connection to the middle to add the same number of strings, the larger the base, the slower.
Test with the following program:
<%
Dim tttt1,ttt2
Session ("II") =0
For Sn=0 to 5
Ttt1=now ()
' Txt= ' "
For I=0 to 10000
Txt= "a" &txt
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next
%>
For the same long byte character connection, the Chinese character is 4 times times faster than English, and is tested by the following program
<%

Dim tttt1,ttt2
For Sn=0 to 5
Ttt1=now ()
Txt= ""
For i=0 to 20000
Txt= "Man" &txt
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next

Txt= ""
For Sn=0 to 5
Ttt1=now ()
Txt= ""
For i=0 to 20000
txt= "AA" &txt
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next

%>
Using a For loop is much faster than a do-while loop, testing with the following program, although there is one more variable in the For loop,
<%
Dim tttt1,ttt2

For Sn=0 to 5
Ttt1=now ()
I=0
Do While i<=100000
I=i+1
Loop
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next

For Sn=0 to 5
Ttt1=now ()
Ii=0
For i=0 to 100000
Ii=ii+1
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& "<br>"
Next
%>
A session that defines 5,000 characters does not take much longer than the definition of 5,000 sessions with 5,000 string lengths, with a time lag of just over a second, with more than a minute. It took a lot of time to generate this 5,000-character variable, <%
Dim tttt1,ttt2
C= "a"
For Sn=0 to 5

Session.Abandon
Ttt1=now ()
For I=0 to 5000
Session ("S" &i) =c
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next

For I=0 to 5000
C= "a" &c
Next

For Sn=0 to 5
Session.Abandon
Ttt1=now ()
For I=0 to 5000
Session ("S" &i) =c
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next


%>


This program is very slow from sn=3, and the front is very fast.
<!--#include file= "filetou.asp"-->
<%
Dim tttt1,ttt2
For Sn=0 to 5
Ttt1=now ()
For I=1 to 20
sql = "SELECT name from user where name = ' O '"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
RS ("name") = "Ah Yu"
Rs.update
Rs.close
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next


%>


And that's a lot quicker. It seems to take time to build objects, and there is no difference between the speed of move 0,1 and MoveFirst.
<!--#include file= "filetou.asp"-->
<%
sql = "SELECT name from user where name = ' O '"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
Dim tttt1,ttt2
For Sn=0 to 5
Ttt1=now ()
For I=1 to 700
RS ("name") = "Ah Yu"
Rs.update
Rs.movefirst
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next
%>

And these two ways, the latter is 3 times times slower, may be the latter to requery, but the previous use of RS to build a query and then to change, changed and closed, compared to the fast do not know how much.
<!--#include file= "filetou.asp"-->
<%
sql = "SELECT name from user where name = ' O '"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
Dim tttt1,ttt2

For Sn=0 to 5
Ttt1=now ()
For I=1 to 700
RS ("name") = "Ah Yu"
Rs.update
Rs.movefirst
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next

For Sn=0 to 5
Ttt1=now ()
For I=1 to 700
Sql= "UPDATE user set name = ' O ' WHERE name = ' O '"
Conn.execute sql,0,-1
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"
Next

%>


New 10,000 records who's fast? The first method takes 31 seconds, and the latter is not completed until the timeout has expired. Last but not least one 0, 1000 is the latter half slow.
<!--#include file= "filetou.asp"-->
<%
sql = "SELECT name from user where id=0"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
Dim tttt1,ttt2

Ttt1=now ()
For I=1 to 10000
Rs.addnew
RS ("name") = "Ah Yu a"
Rs.update
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"


Ttt1=now ()
For I=1 to 10000
Sql= "INSERT into User (name) VALUES (' O ' B ')"
Conn.execute sql,0,-1
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"


%>

The following program results show that RS new record is faster, and the deletion is slower, with Conn new slow, but delete quickly.
The results of the run are:
, 3.00000007264316:
, 7.99999998416752:
, 1.99999983888119:
, 0:
Later with Rs new record 5,000, and the conn delete these 5,000, the result is:
, 17.000000202097:
, 1.00000023376197:
Program is:
<!--#include file= "filetou.asp"-->
<%
Dim tttt1,ttt2
Ttt1=now ()
sql = "SELECT name from user where id=0"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
For I=1 to 1000
Rs.addnew
RS ("name") = "Ah Yu a"
Rs.update
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"


Ttt1=now ()
For I=1 to 1000
Sql= "INSERT into User (name) VALUES (' O ' B ')"
Conn.execute sql,0,-1
Next
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"




Ttt1=now ()
sql = "SELECT name from user where name = ' O ' a '"
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,3
Do as not rs.eof
Rs.delete
Rs.update
Rs.move 0,1
Loop
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"


Ttt1=now ()
sql = "Delete from user where name = ' O ' B '"
Conn.execute sql,0,-1
Ttt2=now ()
Tou=ttt2-ttt1
Response.Write sn& "," &tou*24*60*60& ":" &session ("S" &i-1) & "<br>"


%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.