Performance Xi. is it a good way to collect output with a temporary string?
This question comes from the suggestion of my latest article. The core of the problem is the use of buffering, and the use of temporary strings to collect Response.Write output, so that Response.Write can only be invoked once. To test this problem, we modified the ado_11.asp, not every time in the loop with the Response.Write output, but the output is appended to the end of a string, after all records are processed, call Response.Write Output This string (str__01. ASP):
Dim strtable
strtable = ""
' Write headings
strtable = strtable & "< TABLE border=1 >< TR >"
For i = 0 to FldCount-1
strtable = strtable & "< TH >" & FLD (i). Name & "</th >"
Next
strtable = strtable & "</tr >"
' Write Data
Do as Not objrs.eof
strtable = strtable & "< TR >"
For i = 0 to FldCount-1
strtable = strtable & "< TD >" & FLD (i) & "</td >"
Next
strtable = strtable & "</tr >"
Objrs.movenext
Loop
For i = 0 to FldCount-1
Set FLD (i) = Nothing
Next
strtable = strtable & "</table >"
Response.Write (strtable)
The result was not satisfactory. Perhaps we should, as some suggest, use the space function to allocate some spaces to the string so that the program does not have to allocate space at each loop (str__02.asp):
Dim strtable
Strtable = Space (10000)
It seems that the space function does not work as some people suggest. The last rule we get is:
Do not use temporary strings to collect output.