• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to measure the time to render a jsp  RSS feed

 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is a big for loop in my jsp and I want to know how long for that jsp to render in browser, so I write some code like the following


however, I found that the difference in calendar2.getTime() - calendar1.getTime() is much smaller than the actual time for the jsp to render on the browser.
for example, the difference between calendar2.getTime() - calendar1.getTime() may be only 6 seconds, but the actual time for me to see the first line and then the table (created by the big for loop) and then the last line of that jsp in browser (start calcualate when see the first line of jsp in browser and stop when I see the last line of jsp in browser) may take 1 minutes, so why the time is so different?
how to write the code for me to measure the actual time for user seeing the first line and then need to wait until the last line of jsp in browser?

thanks
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not measuring the time for the browser to render anything there. You're measuring the time for the JSP file to be processed on the server. That's not going to include either the time for the network transmission or for the rendering. To measure the rendering time you're going to have to do it client side: i.e. with Javascript.

(Note that the browser does not render the JSP - it renders the HTML generated by the JSP).
 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:You're not measuring the time for the browser to render anything there. You're measuring the time for the JSP file to be processed on the server. That's not going to include either the time for the network transmission or for the rendering. To measure the rendering time you're going to have to do it client side: i.e. with Javascript.

(Note that the browser does not render the JSP - it renders the HTML generated by the JSP).


thanks. then how to measure the html rendering time using javascript?
 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peter tong wrote:
Matthew Brown wrote:You're not measuring the time for the browser to render anything there. You're measuring the time for the JSP file to be processed on the server. That's not going to include either the time for the network transmission or for the rendering. To measure the rendering time you're going to have to do it client side: i.e. with Javascript.

(Note that the browser does not render the JSP - it renders the HTML generated by the JSP).


thanks. then how to measure the html rendering time using javascript?


You can't do that either.

If you use the Firefox web browser, install the Firebug plugin and use it. It will break down the time to process each URL request end-to-end. May not be 100% accurate, but it should show the worst of the offences. As a general rule, the bulk of the time spent on page rendering isn't the rendering itself, however. The time spent fetching the page components and the time spent in JavaScript routines usually dwarfs the actual render time, even though it makes render time appear slow by retarding the overall process.

 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to use scriptlet and javascript and find some strange result:


I expect the javascript start time should after scriptlet end time because scriplet is processed in server and compile scriptlet to html, and javascript is run in client browser, but the result is javascript start time much earlier scriptlet end time!! in fact, the test show that the javascript start time is equal to scriptlet start time. why would this happen?!!

I use localhost as server, is this the cause?

Also, I add

in body onload() event and find the time is much later than the javascript end time, so what does this imply?

thanks!!
 
Lester Burnham
Rancher
Posts: 1337
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in body onload() event and find the time is much later than the javascript end time, so what does this imply?

It means that onload handlers are run after page rendering has finished.
 
Prakash Mani - Attur
Ranch Hand
Posts: 100
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onload will get loaded only after all the images in the page are loaded... the script evaluation time may be much earlier than onload... no surprise..images will get loaded only in the second request... but i do not know why the script time is earlier than scriptlet time.. please someone clarify..
 
Paul Clapham
Sheriff
Posts: 22378
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash Attur wrote:but i do not know why the script time is earlier than scriptlet time.. please someone clarify..

One is the clock time on the client, the other is the clock time on the server. There is no reason to assume the clocks on the two machines are precisely synchronized.
 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Prakash Attur wrote:but i do not know why the script time is earlier than scriptlet time.. please someone clarify..

One is the clock time on the client, the other is the clock time on the server. There is no reason to assume the clocks on the two machines are precisely synchronized.


no, I use localhost to test, so both are my machine clock, and the javascript start time can much earlier than scriptlet end time, says near 10 seconds!!
I really don't know what is the reason.
I just think, is the scriptlet not completely evaluated to html before send to client but is line by line, that is, the first line of scriptlet is evalulated to html and then send to browser, then the next line of scriptlet, if this is the case, then javascript start time can much earlier than the last line scriptlet evaluation time.
Or is it due to localhost problem, or my testing code has problem??

thanks.
 
Paul Clapham
Sheriff
Posts: 22378
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peter tong wrote:I just think, is the scriptlet not completely evaluated to html before send to client but is line by line, that is, the first line of scriptlet is evalulated to html and then send to browser, then the next line of scriptlet, if this is the case, then javascript start time can much earlier than the last line scriptlet evaluation time.
Or is it due to localhost problem, or my testing code has problem??


Yes, that's possible. And if that's the case then it's even less clear what you are measuring, or what the point of the measuring is.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!