How to add a timer to a JSP page?

Want to add a timer before & after a function to exactly get the processing of that function.What additions to be made to the JSP page?
[153 byte] By [Amitpa] at [2007-11-26 21:16:10]
# 1
Hi...Find the code to add timer using Java Script
Chellama at 2007-7-10 2:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

Find the code to add timer control using Script

<SCRIPT LANGUAGE="JavaScript">

var index = 1;

var min1,sec1;

var cmin1,csec1,cmin2,csec2;

var increment = 1;

var incx;

function Minutes(data) {

for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;

return(data.substring(0,i)); }

function Seconds(data) {

for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;

return(data.substring(i+1,data.length)); }

function Display(min,sec) {

var disp = "";

// if(min><=9) disp=" 0";

// else disp=" ";

disp+=min+":";

if(sec<=9) disp+="0"+sec;

else disp+=sec;

return(disp); }

function Down() {

index++;

cmin2=1*Minutes(document.Online_Exam.beg2.value);

csec2=Seconds(document.Online_Exam.beg2.value);

csec2 = csec2 - increment;

csec2 = csec2 + increment;

var elem = document.getElementById("timertext");

elem.innerHTML = "

<span style=\"font-size: 10pt;\">" + Display(cmin2,csec2) + "</span>

";

down=setTimeout("DownRepeat(" + index + "," + increment + ")", increment * 1000);

}

function DownRepeat(ix,inc) {

if( ix == index ) {

incx = inc;

csec2 = csec2 - inc;

if(csec2 < 0) { csec2= csec2 + 60; cmin2--; }

//if( incx > 1 && cmin2 == 1 && csec2 == 0 ) incx = 1;

var elem = document.getElementById("timertext");

elem.innerHTML = "

<span style=\"font-size: 10pt;\">" + Display(cmin2,csec2) + "</span>

";

if((cmin2==0)&&(csec2==0))

//elem.innerHTML = "

<span style=\"font-size: 10pt; color=red\">STOP</span>

";

document.Online_Exam.submit();

else

down=setTimeout("DownRepeat(" + ix + "," + incx + ")", incx * 1000);

}

}

</SCRIPT>

Chellama at 2007-7-10 2:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I want to add a watch which displays current time before the function is callede.g : clientDoc.open(path+"/"+report, 0);And insert a timer after this so that taking the difference would give me the exact time consumed by the function to execute.....
Amitpa at 2007-7-10 2:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
What you can do is check the current time in milliseconds and find the difference. If you google, you can lot of stuff...
baskarpra at 2007-7-10 2:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

protected void doGet(

HttpServletRequest req, HttpServletResponse resp)

throws ServletException, java.io.IOException {

long startTime = System.currenttimeMills();

..........................

long totalTime = System.currenttimeMills() - startTime;

req.setAttribute("totalTime", new Long(totaltime));

}

tolmanka at 2007-7-10 2:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...