extract and substract between start and end-time for " for loop" in asp

Dear Exerts,

I try to extract the total execution time of the for loop in the following asp code
and since vbscript is not doing well  with miilli-second extraction, so I use javascript code
for extracting time in ms from start and ending of for loop.

Now the code is working, it show the Start and End time. But how to
do substraction  on start-time - end time ?

I tried  put  the end-time javascript right after <% %> similar code to the start time  javascript code. But it showed the wrong result that is why I put into head tag for end time javascript code.

Any better approach for doing that ?

Please advise

Rwniceing


<!DOCTYPE html>
<html>
<script language=javascript runat=server> 
var myvar = Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds());
	response.write("Start time in ms: " + myvar );
    </script>
<%
Dim i,a,b,c
for i = 1 to 2e6
a=1234+5678+i
b=1234*5678+i
c=1234/2+i
next
response.write("<br/>(i,a,b,c)=" & i & "=" &  a & "=" & b & "=" &c & "<br/>")
%>
<body>
</body>
<head runat="server">
    <title>Demo Page for Test</title>
    <script language="javascript" type="text/javascript" >
 var a = new Date();
var myvar = Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds());
	document.write("End&nbsp;&nbsp;time in ms: ",myvar);
   </script>
</head>
</html>

Open in new window

LVL 1
rwniceingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
I've struggled with this in the past (regarding time zone offset which also seemed strangely unavailable in ASP/VB). One of the problems when mixing languages and embedded code blocks with server script tags is keeping tabs on which code is executed when. One way to avoid this problem is to wrap the needed (server side) javascript in a function which can be called from (server side) vb script. Your specific situation could be solved as follows:
<%

Option Explicit

Response.Buffer = False ' not needed but lets you see the output as it is produced instead of all at once

%><!DOCTYPE html>
<html>
<body>
    <script language="jscript" runat="server">
	function getTime() {
		var a = new Date();
		return Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds());
	}
    </script>
<%

Dim startTime, endTime

startTime = getTime()
Response.Write "Start time in ms: " & startTime

Dim i,a,b,c
for i = 1 to 2e6
a=1234+5678+i
b=1234*5678+i
c=1234/2+i
next
response.write("<br/>(i,a,b,c)=" & i & "=" &  a & "=" & b & "=" &c & "<br/>")

endTime = getTime()
Response.Write "End&nbsp;&nbsp;time in ms: " & endTime

Response.Write "<br>Elapsed time in ms: " & (endTime - startTime)

%>
</body>
</html>

Open in new window

Note that I added some bells and whistles just for fun...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwniceingAuthor Commented:
<%

Option Explicit

Response.Buffer = False ' not needed but lets you see the output as it is produced instead of all at once

%>

Open in new window


That is why on my topic post code, it will response.write the output after the for loop completion
and the start and end time is also correct but just echo out at the same time that is strange I feel.
Probably it is caused by the setting on response.buffer.
0
rwniceingAuthor Commented:
Done and thanks for your reply
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.