Reputation: 23
I saw some other method of measure with using trace, but I just wonder this method measure correctly...
I overrided each execution of the following:
PreInit
Init
InitComplete
PreLoad
Load
LoadComplete
PreRender
PreRenderComplete
SaveStateComplete
Unload
Then I store the time when the handler execute with using DateTime.Now.Tick...
At the end of Unload I will print out each of their execution time....
So the time above should be the time server spent to generate the page?
I am asking is because I notice some page took like 879ms in total above, but until my browser actually see the page is take few more seconds.
Those few more seconds should be the time that takes to download the page from server?
Thanks in advance.
Upvotes: 2
Views: 7997
Reputation: 1251
At the very top of you .aspx page if you set the Trace flag it will give you a pretty good readout of how much each of the above events took without having to add any additional event handlers. E.g.
<%@ Page Trace="true" Title=...
In your code behind, if there are any other events/functions you want to measure, you can add
Page.Trace("start of something interesting");
...
Page.Trace("end of something interesting");
And it will automatically measure the time in between the Page.Trace calls.
Upvotes: 0
Reputation: 31435
Yes, there's time for the code to run and the time for the browser to get the response from the server and output it to the screen. You can measure the front-end work using a variety of measuring sites:
To determine the timing for processing of the code, I would use the StopWatch
class instead of using DateTime
. DateTime is more precise to the decimal point, but less accurate. StopWatch
is designed exactly for that and would be better to use to calculate the timing. Avoid calling it a lot though, as that itself will add overhead to the page processing. I would create a new StopWatch()
then call Start at the very beginning, then call stop at the very end. Then spit out the elapsed time after.
Upvotes: 3
Reputation: 20100
in global.asax
namespace aaaaa
{
public class Global : System.Web.HttpApplication
{
private Stopwatch sw = null;
protected void Application_BeginRequest(object sender, EventArgs e)
{
sw = Stopwatch.StartNew();
}
protected void Application_EndRequest(object sender, EventArgs e)
{
if (sw != null)
{
sw.Stop();
Response.Write("took " + sw.Elapsed.TotalSeconds.ToString("0.#######") + " seconds to generate this page");
}
}
}
}
Upvotes: 4
Reputation: 306
If you are just looking for overall time, why not just look at the time-taken value in your IIS logs?
The extra time in the browser could be a lot of things. Fetching, Images, CSS, javascript files, javascript running in the page, and the client rendering of the HTML itself. If you want to get a better feel for what is actually happening and when fire up Fiddler and then reload your page and look at what happened in Fiddler.
Upvotes: 3