I found a false thread opened with ASP on the Internet, and foundProgramSimilar to that in the past, however, we used VB, picked it up, and stored it.
1. The principles of the experiment are the same. The web server supports multiple threads and sends multiple HTTP requests to the server on the same page to complete our work. First, try to write two TXT files at the same time on a page to compare the write time difference.CodeAs follows: <%
Startime = timer ()
''' ---------- Multithreading implemented by ASP ----------''
Function runthread ()
Dim HTTP
Set HTTP = server. Createobject ("msxml2.xmlhttp ")
HTTP. Open "get", "http: // 127.0.0.1/thread. asp? Action = B ", false
HTTP. Send ()
End Function
Function ()
Dim content, filepath, myfile
Content = now () & CHR (30) & timer ()
Filepath = server. mappath ("a.txt ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set myfile = FSO. createtextfile (filepath, true)
Myfile. Write (content)
Myfile. Close
End Function
Function B ()
Dim content, filepath, myfile
Content = now () & CHR (30) & timer ()
Filepath = server. mappath ("B .txt ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set myfile = FSO. createtextfile (filepath, true)
Myfile. Write (content)
Myfile. Close
End Function
If (request. querystring ("action") = "") then
Runthread ()
A ()
Else
B ()
End if
%> Script execution time: <% = fix (timer ()-startime) * 1000) %> the result after MS is displayed: the time in file a and file B is basically the same. 2. for example, I capture the HTML code of two pages at the same time, one Sohu homepage and the other Sina homepage in two ways: the other is regular sequential code execution, single-threaded execution. One is the multi-threaded execution. Compare the page completion time with the following code: testspeed1.asp: <%
Startime = timer ()
Function gethttppage (URL)
On Error resume next
Dim HTTP
Set HTTP = server. Createobject ("msxml2.xmlhttp ")
HTTP. Open "Post", URL, false
HTTP. Send ()
If HTTP. readystate <> 4 then exit function
Gethttppage = bytes2bstr (HTTP. responsebody)
Contents = gethttppage
Response. Write "<XMP>"
Response. Write (contents)
Response. Write "</XMP>"
Set HTTP = nothing
If err. Number <> 0 then err. Clear
End Function
Function bytes2bstr (VIN)
Dim strreturn
Dim I, thischarcode, nextcharcode
Strreturn = ""
For I = 1 to lenb (VIN)
Thischarcode = ASCB (midb (Vin, I, 1 ))
If thischarcode <& h80 then
Strreturn = strreturn & CHR (thischarcode)
Else
Nextcharcode = ASCB (midb (VIN, I + 1, 1 ))
Strreturn = strreturn & CHR (clng (thischarcode) * & h100 + CINT (nextcharcode ))
I = I + 1
End if
Next
Bytes2bstr = strreturn
End Function
Gethttppage ("http://www.sohu.com /")
Gethttppage ("http://www.sina.com.cn /")
%> Script execution time: <% = fix (timer ()-startime) * 1000) %> MS testspeed2.asp: <%
Startime = timer ()
Function gethttppage (URL)
On Error resume next
Dim HTTP
Set HTTP = server. Createobject ("msxml2.xmlhttp ")
HTTP. Open "Post", URL, false
HTTP. Send ()
If HTTP. readystate <> 4 then exit function
Gethttppage = bytes2bstr (HTTP. responsebody)
Contents = gethttppage
Response. Write "<XMP>"
Response. Write (contents)
Response. Write "</XMP>"
Set HTTP = nothing
If err. Number <> 0 then err. Clear
End Function
Function bytes2bstr (VIN)
Dim strreturn
Dim I, thischarcode, nextcharcode
Strreturn = ""
For I = 1 to lenb (VIN)
Thischarcode = ASCB (midb (Vin, I, 1 ))
If thischarcode <& h80 then
Strreturn = strreturn & CHR (thischarcode)
Else
Nextcharcode = ASCB (midb (VIN, I + 1, 1 ))
Strreturn = strreturn & CHR (clng (thischarcode) * & h100 + CINT (nextcharcode ))
I = I + 1
End if
Next
Bytes2bstr = strreturn
End Function
Function runthread ()
Dim HTTP
Set HTTP = server. Createobject ("msxml2.xmlhttp ")
HTTP. Open "get", "http: // 127.0.0.1/thread. asp? Action = B ", false
HTTP. Send ()
End Function
Function ()
Gethttppage ("http://www.sohu.com /")
End Function
Function B ()
Gethttppage ("http://www.sina.com.cn /")
End Function
If (request. querystring ("action") = "") then
Runthread ()
A ()
Else
B ()
End if
%> Script execution time: <% = fix (timer ()-startime) * 1000) %> result of the MS running time: times testspeed1 run time Ms testspeed2.asp run time MS 1 15593 13078 2 13343 14375 3 12828 12515 4 12437 12125 5 12109 6 11734 12281 7 12140 12703 8 12062 9 13468 12656 10 12328 or more once a page is complete, another page is executed again. Whoever goes first is arbitrary. An exception occurred in a record. To avoid network problems, change the test address to the local HTTP address for the following five times: // 127.0.0.1 11 109 46 12 62 13 62 48 14 78 64 15 62 46 or more 5 times is executed on one page after another. Whoever goes first is arbitrary. Result: It seems to be faster ...........