[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-08-29
3
Medium Priority
?
263 Views
Last Modified: 2014-08-29
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

0
Comment
Question by:rwniceing
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40292389
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
 
LVL 1

Author Comment

by:rwniceing
ID: 40292400
<%

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
 
LVL 1

Author Closing Comment

by:rwniceing
ID: 40292406
Done and thanks for your reply
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question