title: Capturing ASP.Net Server Execution time without Network Latency
body: <p>I need to capture the amount of time that ASP.net takes to execute each page request in my application, but I need to exclude any network latency.  I am currently capturing render times by using the StopWatch class and starting the stopwatch during the OnInit method of the page lifecycle and stopping it after the Unload method completes.  It seems that the Unload method includes the time it takes send the request to the client, thus including any internet/network latency.  What is the last possible point I could stop the stopwatch in the Page Life Cycle that would not include the time it takes to send the request to the client.  Would it be directly before the Unload event?</p>
  
  <p>Related question: Does ASP.net finish building the response before it starts sending to the client? Or does it start sending asynchronously, while the response is being formed?  </p>
  
  <p>I am using ASP.Net 2.0 with IIS 5 currently.</p>
  
  <p>I have this code in a class that all of my pages inherit from:</p>
  
  <pre><code>readonly Stopwatch _serverExecutionTime = new Stopwatch();
  
  protected override void OnInit(EventArgs e)
  {
      _serverExecutionTime.Start();
      base.OnInit(e);
  }    
  
  protected override void OnUnload(EventArgs e)
  {
      _serverExecutionTime.Stop();
      base.OnUnload(e);
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried capturing the execution time at the end of the OnRender method, at the start of the OnUnload method and at the end of the OnUnload method.  In all three cases the difference in times was at most 1 millisecond.  Even when testing this from a client in Europe to a server in the USA, the times were identical.  So I think that I am missing something here.</p>