View Full Version : page generation time
10-18-2003, 12:47 PM
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 :D
10-18-2003, 03:48 PM
what do you mean by , cant open the DLL
You can use Timer for that. Timer returns the number of seconds since midnigth
Your other code
response.write("Execution took " & Timer - startt & " seconds")
10-19-2003, 09:13 PM
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
10-20-2003, 07:36 AM
I think I added incorrect info..
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
if Timer < startt then
endt=Timer + 86400 'number of seconds in 1 day. This compensates the jump from 86399 to 86400
elaps = endt - startt
elaps=Timer - startt
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")
10-22-2003, 06:06 AM
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...
10-23-2003, 05:51 PM
dad! moderators are smposed to all be like 70 :p
well.. they are in my head 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
nope.. it shows "Execution took 64366.77 seconds".. which cant be right man. if it should work, what did i miss?
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 :D
10-23-2003, 06:38 PM
nevrermind, i managed to work out a way of doing it :D
<%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"
%> 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 :thumbsup:
10-24-2003, 02:05 AM
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. :eek:
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.
10-24-2003, 03:57 PM
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.
10-28-2003, 09:37 AM
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 :p
10-29-2003, 01:42 AM
11-02-2003, 01:56 AM
Oh, come on guys!! Why has no-one mentioned the VBScript FormatNumber() function? :p
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.
11-02-2003, 03:38 AM
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.