Using the Stopwatch class (available from .NET 2.0) we can display the amount of time taken to process the page. Stopwatch gets you the most accurate time elapsed in milliseconds or ticks and the code below displays the time taken for the entire page life cycle to be processed.
Stopwatch class is available in System.Diagnostics namespace.
[code:c#]public partial class TestPage : System.Web.UI.Page {
// when the page is instantiated we start our stopwatch
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
protected void Page_Load (object sender, EventArgs e) {
// your page load code
}
// override the Render method
protected override void Render (HtmlTextWriter writer) {
// get the total time elapsed. this will be in milliseconds
// and I converted it to seconds
float _seconds = ((float)sw.ElapsedMilliseconds/1000);
// display the information in a label
this.lblPageGeneratedIn.Text = "Page generated in " +
_seconds.ToString() + " seconds";
base.Render(writer);
}
class="kwd">}[/code]
E Screw