Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts

    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

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opening

    what do you mean by , cant open the DLL

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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")

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #5
    Regular Coder
    Join Date
    Mar 2003
    Posts
    241
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Edit: I think I added incorrect info..
    Last edited by Caffeine; 10-20-2003 at 09:04 AM.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 11:39 PM.

  • #7
    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
    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. ;)

  • #8
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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 07:00 PM.

  • #9
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #10
    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
    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.
    Last edited by whammy; 10-24-2003 at 03:09 AM.
    Former ASP Forum Moderator - I'm back!

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

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #13
    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
    CInt()
    Former ASP Forum Moderator - I'm back!

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

  • #14
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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"

  • #15
    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
    ...
    Former ASP Forum Moderator - I'm back!

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •