Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2003, 12:47 PM   PM User | #1
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
page generation time

i was quite suprised i could not find this anywhere as it seems to be quite popular, particularly with php users

anyway, i am trying to make a page generation timer, and i think i cna do this with a start time at the op of the page and an end time at the end of it and use hte difference to say the time taken, however, i do not know any way to get this to fractions of seconds (2dp would be enough)

so far, the closest i have been is on this page http://www.cs.niu.edu/%7Ez951259/comlinks.html

but it requires the use of a dll, which i do not want to do unless it is absolutely necisary, particularly as i cant even open the dll in visual studio in non-hex form. besides, it was written in 1997 and i have windows server 2003 running so i thought there might be a better way of doing it now,

any help would be.... err....very helpful
ghell is offline   Reply With Quote
Old 10-18-2003, 03:48 PM   PM User | #2
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
opening

what do you mean by , cant open the DLL
angiras is offline   Reply With Quote
Old 10-18-2003, 08:21 PM   PM User | #3
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
You can use Timer for that. Timer returns the number of seconds since midnigth

Code:
dime start
startt=Timer
Your other code
response.write("Execution took " & Timer - startt & " seconds")
raf is offline   Reply With Quote
Old 10-19-2003, 09:13 PM   PM User | #4
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
y wud i want a time from midnight.. i wanted a time diff in more accurate than seconds.. and hthe prob ws that i didnt want to put a 6yr old dll on my new ws2k3 server because ther eis probably a better way of doing it now.. and i duno how to take it if incase it is a virus or watever
ghell is offline   Reply With Quote
Old 10-20-2003, 07:36 AM   PM User | #5
Caffeine
Regular Coder

 
Join Date: Mar 2003
Posts: 241
Thanks: 0
Thanked 0 Times in 0 Posts
Caffeine is an unknown quantity at this point
Edit: I think I added incorrect info..

Last edited by Caffeine; 10-20-2003 at 08:04 AM..
Caffeine is offline   Reply With Quote
Old 10-20-2003, 08:18 AM   PM User | #6
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Short answer : because it's a proven method. I've used it and it worked fine for me
Longer answer : you ALWAYS need a third reference point to calculate the difference between two points and it doesn't matter how far away this reference point is. It's as simple and complicated as that. Now PHP has a better sollution, cause you can get the number of elapsed seconds since the unix epoch. Buth ASP only enables you to get the number of elapsed seconds since midnight. The result will be the same UNLESS you pass midnight during the scripts execution. But that's a realy slim chance.
You can counter that with
Code:
dim elaps
if Timer < startt then
  dim endt
  endt=Timer + 86400    'number of seconds in 1 day. This compensates the jump from 86399 to 86400
  elaps = endt - startt
else
  elaps=Timer - startt
end if
response.write("Execution took " & elaps & " seconds")
<edit> I looked at some code where is used it, an i see i've used Round() there, when i display the result. It just looks better if you always display an fixed number of decimals. I rounded it to 5 decimals so i suppose you can have an even more accurate measurement.
The last line would then look like
response.write("Execution took " & Round(elaps,5) & " seconds")
</edit>

Last edited by raf; 10-20-2003 at 10:39 PM..
raf is offline   Reply With Quote
Old 10-22-2003, 06:06 AM   PM User | #7
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
Why does this sound like triangulation? Heh... sorry to be off-topic but I was having a very similar discussion with my Dad a couple of nights ago...
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 10-23-2003, 05:51 PM   PM User | #8
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
dad! moderators are smposed to all be like 70
well.. they are in my head newho

newho...
can some1 please translate raf's post into like.. english or somit.... do i need to use that dll or what because that script will no work on its own...err.....will it?.. ill try but it doesnt look like it should

-Edit-
nope.. it shows "Execution took 64366.77 seconds".. which cant be right man. if it should work, what did i miss?

-Edit2-
wait a min.. am i sposed to put this script at start and end an make hte diff? ill try that.. it looks like it should work too.. ty if it does

Last edited by ghell; 10-23-2003 at 06:00 PM..
ghell is offline   Reply With Quote
Old 10-23-2003, 06:38 PM   PM User | #9
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
nevrermind, i managed to work out a way of doing it
Code:
<%starttime = timer%>

<!--html, body, head etc goes in here-->

<%If starttime <> "" then%><br>
Page Generation: <%
endtime = timer
timediff = round(endtime - starttime,3)
if timediff*1000 Mod 10 = "0" then timediff = timediff & "0"
Response.Write timediff
%> Seconds<%End If%>
this displays to 3dp even if it is 0.01 s, so it would display 0.010
i know its probably not the best way to write it but its how i like doing it, im probably guna be told i should change things to strings before adding "0" to them and stuff like that but who cares, it works
ghell is offline   Reply With Quote
Old 10-24-2003, 02:05 AM   PM User | #10
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
Don't worry, I'm almost 33... heheh.

If you want just classic ASP stuff you could use Timer() in VBScript, look it up on MSDN.

Not guaranteed to be accurate but it should give you a fairly good estimate.

Oops... looks like you did that!

P.S. That's one of the quirky things about VBScript, everything is a "variant", so you don't necessarily have to define the datatype, it tries to do it for you.

Drawbacks are it takes a bit longer (probably in milliseconds), and it allows for sloppy code. Not to mention I've seen quite a few very weird bugs creep in because of this kind of practice. I'm assuming that's why they tried to get away from it in .NET.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)

Last edited by whammy; 10-24-2003 at 02:09 AM..
whammy is offline   Reply With Quote
Old 10-24-2003, 03:57 PM   PM User | #11
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
Just for the record, if you're really interested in page execution times you can have IIS record them into the web server log files since that's one of the optional things that can be added to those log files. While that won't be seen by the end-users it can be seen by those who should care most about execution times.
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 10-28-2003, 09:37 AM   PM User | #12
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
meh, i dont really care but it always makes it look more professional and makes it seem faster too

the whole variant thing, i know it does it automatically, which has good and bad points (good point - with numbers you do not have to set a size, it usually sets the minimum possible)

but sometimes when i add a number to a string (eg when it has letters in it) i get a type mismatch, so it can be a good idea to set it to an integer first.. or..somit like that newho
ghell is offline   Reply With Quote
Old 10-29-2003, 01:42 AM   PM User | #13
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
CInt()
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 11-02-2003, 01:56 AM   PM User | #14
M@rco
Regular Coder

 
Join Date: Oct 2003
Location: London, UK
Posts: 411
Thanks: 0
Thanked 1 Time in 1 Post
M@rco is an unknown quantity at this point
Oh, come on guys!! Why has no-one mentioned the VBScript FormatNumber() function?

e.g. FormatNumber(0.01, 3) --> 0.010

But bear in mind that the Timer() function has a resolution (i.e. accuracy limit) of just under 4 ms, so I'd stick to 2 decimal places if I were you.

__________________
Marcus Tucker / www / blog
Web Analyst Programmer / Voted SPF "ASP Guru"
M@rco is offline   Reply With Quote
Old 11-02-2003, 03:38 AM   PM User | #15
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
...
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:39 AM.


Advertisement
Log in to turn off these ads.