What is the best way to measure the code run time in ASP.NET page?
Here is my code, trying to time the page load and writing to log.
private Stopwatch PageTimer = null;
protected void Page_Init(Object Src, EventArgs E)
{
if (!IsPostBack)
{
PageTimer = new Stopwatch();
PageTimer.Start();
}
}
protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
PageTimer.Stop();
Logger.SectionEnd("PageTimer", PageTimer, "", true);
}
base.OnPreRender(e);
}