Forum Moderators: open

Message Too Old, No Replies

ASP Timer

This page was generated in ... seconds

         

chris_f

1:34 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi All,

I was wondering if you could help. I have seen it done on many sites and was looking for some simple could. At the bottom of every page on one of my sites I want the sentence:

This page was generated in ... seconds

Where ... is the amount of time the sever took to create the page.

Can anyone help as most of the code I have seen is very complicated.

Chris

Dreamquick

1:53 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have the Timer() function in IE5/IIS5 onwards which returns the current time in terms of seconds since midnight (but it does come with a decimal).

Store the value this generates twice - once at the start on the script, once at the end of the script then work out the difference.

<%
Dim fVal(1), i

fVal(0) = CSng( Timer )
Response.Write fVal(0) & "<BR>"

For i = 1 to 500000
Sqr( iCount )
Next

fVal(1) = CSng( Timer )
Response.Write fVal(1) & "<BR>"
%>

This script took <%= CSng( fVal(1) - fVal(0) ) %> seconds to execute.

n.b. the "For" loop is simple there to make it do some work and eat some time - you might need to alter the numbers to get it to take more or less time depending on your system speed.

Hope that was simple enough / helps!

- tony

[edited by: Dreamquick at 1:56 pm (utc) on Dec. 20, 2002]

wardbekker

1:55 pm on Dec 20, 2002 (gmt 0)

10+ Year Member



even lesser code


Dim startTime
startTime = Timer()

somewhere in the bottom of the page:


This page was generated in <%=Round((Timer - StartTime)*1000) %> ms

Dreamquick

1:59 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is simpler - you win! :)

The reason I chose the two variable approach is that with both of them you can use the start and end times over and over again without having them change while you work with them.

- Tony

chris_f

2:14 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wardbekker,

Are you one of them people who codes site that have 12,000 pages and only take up 1 bit of space ;).

Thanks, The code works a treat.
Chris.