When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
Technology Jobs
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.
Published: Wednesday, January 02, 2002

Performance Metrics for the ASP Response Object

By James Greenwood


Introduction
Ever since the first version of ASP there have been arguments over what is the best way to produce ASP pages - whether to take it from an HTML point of view, and intersperse bits of ASP where necessary, or whether to treat the page as a program that simply outputs HTML through a buffer/stream. This article briefly compares the performance of three different methods when producing identical output, and provides an insight into what performance we can expect from the ASP.Net platform.

- continued -

'

The article begins with a description of the three methods being tested, and then describes the test being performed and the code being executed. The performance figures are then given for a standard PIII workstation class machine. This is then put along side the equivalent implementation in ASP.Net, with the performance figures for this also being tabulated. Finally, a conclusion of the results is given.

Different Methods
The three methods below are described in order of structure. The first is the most unstructured type of code, the second being more structured, and the third making use of more advanced constructs.

    Method 1
    This method is the one most commonly used, especially by those who develop using WYSIWYG environments (such as InterDev's Design View), the use of context-switching. A sample of this is given below:

    <html>
      <body>
        The current date is: <%=Date %>
      </body>
    </html>
    

    This style has also become widespread due to the ease with which designers can hand over pages to developers to "insert where necessary" the dynamic parts of the pages, rather than treating the entire page as one dynamic entity. Other benefits, as laid out above, include the ability to make use of WYSIWYG editors, allowing those less skilled in HTML to produce ASP pages.

    Method 2
    The second method is that quite often preferred by developers who come from a more formal background, rather than designers that have learned to code. A sample of this would be:

    <%
      Sub Main()
         Response.Write "<html>" & vbcrlf
         Response.Write "  <body>" & vbcrlf
         Response.Write "    The current date is: " & Date & vbcrlf
         Response.Write "  </body>" & vbcrlf
         Response.Write "</html>" & vbcrlf
     End Sub
    
     Main
    %>

    The main benefit of this type of code is that it allows simpler analysis of program-flow, easier debugging, and simple conversion to Visual Basic for the benefits of compiled code. Additionally, pages can be developed by more than one programmer simultaneously due to the strict compartmentalization of code into functions.

    Method 3
    The third method is a variation of the second, as can be seen below:

    <%
      Sub Main()
         With Response
             .Write "<html>" & vbcrlf
             .Write "  <body>" & vbcrlf
             .Write "    The current date is: " & Date & vbcrlf
             .Write "  </body>" & vbcrlf
             .Write "</html>" & vbcrlf
         End With
      End Sub
    
      Main
    %>
    

    This method is clearly more appealing, as not only does it require less typing, and produce shorter lines of code, it also allows the Response object to be replaced with another object if the ASP page is converted to producing reports, etc. in a different format. Note that use of the With block is only supported in VBScript version 5.0 and up.

Facts and Figures
To compare these three methods of outputting pages in ASP, a simple test is to be performed - a loop that outputs a single character, a period - .. A timer will be started just before this loop is entered, and stopped as soon as the loop exits, removing the remainder of the page from the equation. To allow for a meaningful comparison that isn't on the scale of nanoseconds, this loop will execute 500,000 times (the number was picked as it should be short enough for pages not to time-out, even when the maximum execution time is set to a low figure). Of course a component could be used to more accurately time the execution of these tests, but using the Timer function will be "good enough" for our test results - after all, we are just interested in showing what technique is the most efficient, not the specific times for each technique.

The test code is as follows:

<%
  'Initialize timer
  dInitTime = Timer

  'First Method
  For n = 1 To 500000
     %>.<%
  Next
 
  'Output time
  fPeriod = FormatNumber(Timer - dInitTime, 3, True)
  Response.Write "<br>Method 1 Time: " & fPeriod & "<p>"

  'Repeat process...
  dInitTime = Timer

  'Second Method
  For n = 1 To 500000
      Response.Write "."
  Next
  
  fPeriod = FormatNumber(Timer - dInitTime, 3, True)
  Response.Write "<br>Method 2 Time: " & fPeriod & "<p>"


  dInitTime = Timer

  'Third Method
  With Response
    For n = 1 To 500000
        .Write "."
    Next
  End With

  fPeriod = FormatNumber(Timer - dInitTime, 3, True)
  Response.Write "<br>Method 3 Time: " & fPeriod & "<p>"
%>

This gives a figure in seconds, accurate to three decimal places - easily enough for an accurate comparison of the results.

To view the results for the above test, read on to Part 2. Also, in Part 2 we'll examine the same tests when executed through an ASP.NET Web page!

  • Read Part 2!



  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article