Calculate the Time taken by a web page to execute

How to Calculate time taken by a web page to excute? Or Calculate execution time of a web page?
Here is a simple solution help you find out the number of Milliseconds or seconds or minutes taken by a web page to execute.


1.    Copy below code in your Global.asax file.
2.    Once you run your .aspx page, below code will display Number of time taken by a web page to execute.


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;
        // Display time in Milliseconds
        Response.Write("Number of Milliseconds for execution of this page "+" - "+ ts.TotalMilliseconds);


        // Display time in Seconds
        Response.Write("Number of Seconds for execution of this page " + " - " + ts.TotalSeconds);

        // Display time in minutes
        Response.Write("Number of Minutes for execution of this page " + " - " + ts.TotalMinutes);        
}