calculate the time taken by a web page to execute

Posted by Ddd under ASP.NET category on | Points: 40 | Views : 3506
//Write this coding in the Global.asax file

//when you run .aspx page, you can see the execution time in millseconds.

 void Application_BeginRequest(object sender, EventArgs e)
Context.Items.Add("startime", DateTime.Now);
void Application_EndRequest(object sender, EventArgs e)
//Get the start time
DateTime dt=(DateTime)Context.Items["startime"];
//calculate the time difference between start and end of request
TimeSpan ts = DateTime.Now-dt;
Response.Write("number of milleseconds for execution"+"--"+ts.TotalMilliseconds);


Comments or Responses

Login to post response