overall product performance. Minimal logging can be useless from a developer's perspective. The balance has to be achieved somehow. This falls under designing, and product drives the need to implement it.
String Manipulation
String manipulations can be very expensive from a performance perspective. If ASP/JSP code is looping to formulate a string to send back to the client browser, efforts should be made to avoid this process. For example, many people build a string in a loop like this:
s = "
helps when the page is HTML based. However, with asp and jsp pages, it becomes too expensive to send all that data over the wire each time the request is made. The data can be dynamically displayed. No doubt, it is confusing and tedious from a programming perspective to use "document.write" to render HTML, but it does save network bandwidth as script files can be locally cached. There are many cascading style sheet editors on the market to facilitate this process of attaching cascading style sheets to HTML/ASP/JSP pages.
For Each fld in rs.Fields
s = s & "
Next
While Not rs.EOF
s = s & vbCrLf & "
For Each fld in rs.Fields
s = s & "
Next
s = s & "
rs.MoveNext
Wend
s = s & vbCrLf & "
" & vbCrLf""""
| " & fld.Name & " |
|---|
| " & fld.Value & " |
" & vbCrLf
Response.Write s
There are several problems with this approach. The first is that repeatedly concatenating a string takes quadratic time; less formally, the time that it takes to run this loop is proportional to the square of the number of records, times the number of fields. A simpler example should make this clearer:
s = ""
For i = Asc("A") to Asc("Z")
s = s & Chr(i)
Next
On the first iteration, you get a one-character string, "A." On the second iteration, VBScript has to reallocate the string and copy two characters ("AB") into "s." On the third iteration, it has to reallocate "s" again and copy three characters into "s." On the Nth (26th) iteration, it has to reallocate and copy "N" characters into "s." That's a total of 1+2+3+...+N which is N*(N+1)/2 copies.
In the recordset example above, if there were 100 records and five fields, the inner loop would be executed 100*5 = 500 times, and the time taken to do all the copying and reallocation would be proportional to 500*500 = 250,000. That's a lot of copying for a modest-sized recordset.
In this example, the code could be improved by replacing the string concatenation with Response.Write() or inline script (<% = fld.Value %>). If response buffering is turned on (as it should be), this will be fast, as Response.Write just appends the data to the end of the response buffer. No reallocation is involved and it's very efficient.
In the particular case of transforming an ADO recordset into an HTML table, consider using GetRows or GetString.
If you concatenate strings in JScript, it is highly recommended that you use the += operator; that is, use
s += "some string", not s = s + "some string"
Miscellaneous
Here are a few other considerations when taking performance measures:
- Different isolation levels with IIS configuration should be tested in-depth. There are three isolation levels: low, medium, and high.
- COM components should be configured appropriately for high performance. There are three configuration options: unconfigured, configured as a library option, and configured as a server option.
- Use option explicit at the top of your asp pages. This forces developers to declare all of their variables. Declared variables






