Page Generation Time

  • Thread starter Thread starter Nick Ashley
  • Start date Start date
N

Nick Ashley

I am wanting to include a message in the footer of my application which
displays the server-side page generation time. An example of what I
want is at http://p2p.wrox.com/ (This page was generated in x seconds.)

I am aware that I can find this information by adding trace="true" to
the page directive, but is there any way to access the information
otherwise (as this is something I want incorporated into the design,
not to be used for debugging)

If not, I would like some help on manually generating this myself. I
would like it to be done in the master page (or some other way where I
don't have to include it on every page I create) So would like to time
from the earliest point possible, to the latest possible (with still
being able to output to the browser). Any help would be greatly
appreciated!
 
Well, you could simply do it at the start of onInit and at the end of
onPreRender in your master page.

You could actually start a little earlier, like in Application_BeginRequest


Begin_Request
HttpContext.Current.Items.Add("startTime", DateTime.Now);


onpreRender


if (HttpContext.Current.Items["startTime"] != null)
{
footerLiteral.Text =
DateTime.Now.Subtract((DateTime)HttpContext.Current.Items["startTime"]).TotalSeconds.ToString();
}


Karl
 
Hmmm, wouldn't you have to use something like :


DateTime.Now.ToString("ss.fffffff")

....in order to get a meaningful elapsed time ?



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

Karl Seguin said:
Well, you could simply do it at the start of onInit and at the end of onPreRender in your master
page.

You could actually start a little earlier, like in Application_BeginRequest


Begin_Request
HttpContext.Current.Items.Add("startTime", DateTime.Now);


onpreRender


if (HttpContext.Current.Items["startTime"] != null)
{
footerLiteral.Text =
DateTime.Now.Subtract((DateTime)HttpContext.Current.Items["startTime"]).TotalSeconds.ToString();
}


Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Nick Ashley said:
I am wanting to include a message in the footer of my application which
displays the server-side page generation time. An example of what I
want is at http://p2p.wrox.com/ (This page was generated in x seconds.)

I am aware that I can find this information by adding trace="true" to
the page directive, but is there any way to access the information
otherwise (as this is something I want incorporated into the design,
not to be used for debugging)

If not, I would like some help on manually generating this myself. I
would like it to be done in the master page (or some other way where I
don't have to include it on every page I create) So would like to time
from the earliest point possible, to the latest possible (with still
being able to output to the browser). Any help would be greatly
appreciated!
 
Dunno... ??? :)

--
http://www.openmymind.net/
http://www.codebetter.com/


Juan T. Llibre said:
Hmmm, wouldn't you have to use something like :


DateTime.Now.ToString("ss.fffffff")

...in order to get a meaningful elapsed time ?



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%23aLCfeV%[email protected]...
Well, you could simply do it at the start of onInit and at the end of
onPreRender in your master page.

You could actually start a little earlier, like in
Application_BeginRequest


Begin_Request
HttpContext.Current.Items.Add("startTime", DateTime.Now);


onpreRender


if (HttpContext.Current.Items["startTime"] != null)
{
footerLiteral.Text =
DateTime.Now.Subtract((DateTime)HttpContext.Current.Items["startTime"]).TotalSeconds.ToString();
}


Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Nick Ashley said:
I am wanting to include a message in the footer of my application which
displays the server-side page generation time. An example of what I
want is at http://p2p.wrox.com/ (This page was generated in x seconds.)

I am aware that I can find this information by adding trace="true" to
the page directive, but is there any way to access the information
otherwise (as this is something I want incorporated into the design,
not to be used for debugging)

If not, I would like some help on manually generating this myself. I
would like it to be done in the master page (or some other way where I
don't have to include it on every page I create) So would like to time
from the earliest point possible, to the latest possible (with still
being able to output to the browser). Any help would be greatly
appreciated!
 
Karl,

I implemented what you suggested, and it worked beautifully.

Juan, I'm not sure what you are suggesting, is it just an alternate way
to format? I took Karl's advice, then simply added Math.Round to round
the result to the nearest 100th of a second.

Thanks for the help guys, I appreciate it.

Dunno... ??? :)

--http://www.openmymind.net/http://www.codebetter.com/

Juan T. Llibre said:
Hmmm, wouldn't you have to use something like :

...in order to get a meaningful elapsed time ?
Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
===================================
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in messagenews:%23aLCfeV%[email protected]...
Well, you could simply do it at the start of onInit and at the end of
onPreRender in your master page.
You could actually start a little earlier, like in
Application_BeginRequest
Begin_Request
HttpContext.Current.Items.Add("startTime", DateTime.Now);
onpreRender
if (HttpContext.Current.Items["startTime"] != null)
{
footerLiteral.Text =
DateTime.Now.Subtract((DateTime)HttpContext.Current.Items["startTime"]).TotalSeconds.ToString();
}
Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
I am wanting to include a message in the footer of my application which
displays the server-side page generation time. An example of what I
want is athttp://p2p.wrox.com/(This page was generated in x seconds.)
I am aware that I can find this information by adding trace="true" to
the page directive, but is there any way to access the information
otherwise (as this is something I want incorporated into the design,
not to be used for debugging)
If not, I would like some help on manually generating this myself. I
would like it to be done in the master page (or some other way where I
don't have to include it on every page I create) So would like to time
from the earliest point possible, to the latest possible (with still
being able to output to the browser). Any help would be greatly
appreciated!
 
re:
added Math.Round to round the result to the nearest 100th of a second

Seconds are not enough to establish the time elapsed between events,
although for a total ET it would work, if you round it as you did.

Also, you have to watch out for the server caching the page.
The results of caching distort the real time it takes.

OnInit and Render seem to happen simultaneously when the page is cached.

Care to share/post your code, so others can benefit ?





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Karl,

I implemented what you suggested, and it worked beautifully.

Juan, I'm not sure what you are suggesting, is it just an alternate way
to format? I took Karl's advice, then simply added Math.Round to round
the result to the nearest 100th of a second.

Thanks for the help guys, I appreciate it.

Dunno... ??? :)

--http://www.openmymind.net/http://www.codebetter.com/

Hmmm, wouldn't you have to use something like :

...in order to get a meaningful elapsed time ?
Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
===================================
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in messagenews:%23aLCfeV%[email protected]...
Well, you could simply do it at the start of onInit and at the end of
onPreRender in your master page.
You could actually start a little earlier, like in
Application_BeginRequest
Begin_Request
HttpContext.Current.Items.Add("startTime", DateTime.Now);
onpreRender
if (HttpContext.Current.Items["startTime"] != null)
{
footerLiteral.Text =
DateTime.Now.Subtract((DateTime)HttpContext.Current.Items["startTime"]).TotalSeconds.ToString();
}
Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
I am wanting to include a message in the footer of my application which
displays the server-side page generation time. An example of what I
want is athttp://p2p.wrox.com/(This page was generated in x seconds.)
I am aware that I can find this information by adding trace="true" to
the page directive, but is there any way to access the information
otherwise (as this is something I want incorporated into the design,
not to be used for debugging)
If not, I would like some help on manually generating this myself. I
would like it to be done in the master page (or some other way where I
don't have to include it on every page I create) So would like to time
from the earliest point possible, to the latest possible (with still
being able to output to the browser). Any help would be greatly
appreciated!
 
Back
Top