Home > .net 2.0, .net 3.0, .net 3.5, c#, Microsoft, Visual Studio 2005, Visual Studio 2008 > Basic Benchmarking in ASP.Net

Basic Benchmarking in ASP.Net

April 10, 2008

I’m not sure why I’ve always rewrote this “simple” code—over and over again, project after project.  I should know better, but perhaps time has gotten the best of me (though I’m betting on lazy).

What code might this be?  The basic “stopwatch” for evaluating page performance and outputing the results to Page.Trace. You can do page speed analysis using Visual Studio 2008, but for quick Trace output, I prefer this method.

The class is almost totally private, but could be expanded later on to log to console, log to files, whatever.

public class BenchmarkToTrace


private TimeSpan ElapsedTime { get; set; }

       private DateTime StartTime { get; set; }

       private DateTime EndTime { get; set; }

       private Page PageToTrace { get; set; }

       private string TraceCategory { get; set; }


       public BenchmarkToTrace(Page pageToTrace, string category)


              PageToTrace = pageToTrace;

TraceCategory = category;

PageToTrace.Trace.IsEnabled = true;



       public void Start()


              StartTime = DateTime.Now;



       public void Stop()


EndTime = DateTime.Now;

ElapsedTime = EndTime – StartTime;




“Start: {0} “ + Environment.NewLine +

“Stop: {1} “ + Environment.NewLine +

“Elapsed: {2}”,

StartTime, EndTime, ElapsedTime));



As far as usage, here’s how I am using the benchmarker to evaluate different data retrieval methods (in this example, measuring Oracle performance):

BenchmarkToTrace bench =

new BenchmarkToTrace(this.Page, “Reports-GetAllBy”);



Reports.GetAllBy(123465789, 3, “2007-2008”);




Reports.GetAllBy(123456789, 4, “2007-2008”);


When I load up the page, I see the trace log:

BenchmarkToTest Results

Cool, and I won’t rewrite this NEXT time.

  1. No comments yet.
  1. April 16, 2008 at 12:00 pm
Comments are closed.
%d bloggers like this: