Performance Metrics for the ASP Response ObjectBy James Greenwood
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.
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.
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.
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:
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.
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:
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.
The third method is a variation of the second, as can be seen below:
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
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:
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!