Reputation: 1073
I have a JSP contains high amount of HTML code. There are many inner divs, spans and h2 tags. The HTML code is generated by scriplets using some for loops.
I measure the scriptlet process by using the following :
<% long time = System.currentTimeMillis(); %>
// here is the entire page data
<% System.out.println("Time : " + (System.currentTimeMillis()-time)); %>
According to this measurement, the process time is 300-350 msecs.
To spot the parts that make the delay, I did something like that :
<% long time = System.currentTimeMillis(); %>
// Some HTML Blocks
<% System.out.println("Time1 : " + (System.currentTimeMillis()-time)); %>
// Another HTML Blocks
<% System.out.println("Time2 : " + (System.currentTimeMillis()-time)); %>
However, I realised that sometimes even if I do the following, even there is no html block between printlns, the time value is still changes !
<% long time = System.currentTimeMillis(); %>
// Some Blocks
<% System.out.println("Time1 : " + (System.currentTimeMillis()-time)); %>
<% System.out.println("Time2 : " + (System.currentTimeMillis()-time)); %>
Output is :
Time1 : 65
Time2 : 208
So what is the thing that slow down my page ? How can I detect the point?
Do the Scriptlets have performance weakness for processing heavy HTML codes?
----- UPDATE ------
Here is the output :
first : 0
Sec : 0
thr : 0
fr : 180
Total : 180
There is nothing between thr and fr but fr value is 180 !
Upvotes: 2
Views: 1255
Reputation: 3915
JSPs are java classes underneath. There shouldn't be any performance impact. Scriptlets are bad practice though, so unless this is just for benchmarking purposes, I wouldn't do it.
There are overhead costs when printing to the console as well. So when you're calculating:
<% System.out.println("Time2 : " + (System.currentTimeMillis()-time)); %>
You're adding all the time it takes to make the println call. If you want a more accurate reading, you should be doing this instead:
<% long time2 = System.currentTimeMillis(); %>
Only calculate the time at the very end of your JSP. Do not calculate/print results in the middle of the JSP as you'll see invalid results.
As an aside, I see you say you're using for loops. You should look at the JSTL core library: https://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/tld-summary.html
Upvotes: 1