Calculating average time

Discussion in 'Python' started by GregM, Jul 7, 2005.

  1. GregM

    GregM Guest

    Hi,
    I'm hoping that someone can point me in the right direction with this.
    What I would like to do is calculate the average time it takes to load
    a page. I've been searching the net and reading lots but I haven't
    found anything that helps too much. I'm testing our web site and hiting
    +6000 urls per test. Here is a subset of what I'm doing.

    import IEC
    #IE controller from http://www.mayukhbose.com/python/IEC/index.php
    from win32com.client import Dispatch
    import time
    import datetime
    from sys import exc_info, stdout, argv, exit
    failedlinks = []
    links = open(testfile).readlines()
    totalNumberTests = len(links)
    ie = IEC.IEController()
    start = datetime.datetime.today()
    # asctime() returns a human readable time stamp whereas time() doesn't
    startTimeStr = time.asctime()
    for link in links:
    start = datetime.datetime.today()
    ie.Navigate(link)
    end = datetime.datetime.today()
    pagetext = ie.GetDocumentText()
    #check the returned web page for some things
    if not (re.search(searchterm, pagetext):
    failedlinks.append(link)
    ie.CloseWindow()
    finised = datetime.datetime.today()
    finishedTimeStr = time.asctime()
    # then I print out results, times and etc.

    So:
    1. Is there a better time function to use?

    2. To calculate the average times do I need to split up min, sec, and
    msec and then just do a standard average calculation or is there a
    better way?

    3. is there a more efficient way to do this?

    4. kind of OT but is there any control like this for Mozilla or
    firefox?

    This is not intended to be any sort of load tester just a url
    validation and page check.

    Thanks in advance.
    Greg.
    GregM, Jul 7, 2005
    #1
    1. Advertising

  2. greg> 1. Is there a better time function to use?

    For this particular scenario I think time.time() is probably what you want:

    cumulative = 0.0
    n = 0
    for link in links:
    t = time.time()
    ie.Navigate(link)
    cumulative += time.time() - t
    n += 1

    print "average page load time:", cumulative/n, "seconds"

    Skip
    Skip Montanaro, Jul 7, 2005
    #2
    1. Advertising

  3. GregM

    GregM Guest

    Thanks Skip. As usual I want to make it harder then it actually is.
    GregM, Jul 7, 2005
    #3
  4. have a look at the "timeit" module aswell

    GregM wrote:
    > Hi,
    > I'm hoping that someone can point me in the right direction with this.
    > What I would like to do is calculate the average time it takes to load
    > a page. I've been searching the net and reading lots but I haven't
    > found anything that helps too much. I'm testing our web site and hiting
    > +6000 urls per test. Here is a subset of what I'm doing.
    >
    > import IEC
    > #IE controller from http://www.mayukhbose.com/python/IEC/index.php
    > from win32com.client import Dispatch
    > import time
    > import datetime
    > from sys import exc_info, stdout, argv, exit
    > failedlinks = []
    > links = open(testfile).readlines()
    > totalNumberTests = len(links)
    > ie = IEC.IEController()
    > start = datetime.datetime.today()
    > # asctime() returns a human readable time stamp whereas time() doesn't
    > startTimeStr = time.asctime()
    > for link in links:
    > start = datetime.datetime.today()
    > ie.Navigate(link)
    > end = datetime.datetime.today()
    > pagetext = ie.GetDocumentText()
    > #check the returned web page for some things
    > if not (re.search(searchterm, pagetext):
    > failedlinks.append(link)
    > ie.CloseWindow()
    > finised = datetime.datetime.today()
    > finishedTimeStr = time.asctime()
    > # then I print out results, times and etc.
    >
    > So:
    > 1. Is there a better time function to use?
    >
    > 2. To calculate the average times do I need to split up min, sec, and
    > msec and then just do a standard average calculation or is there a
    > better way?
    >
    > 3. is there a more efficient way to do this?
    >
    > 4. kind of OT but is there any control like this for Mozilla or
    > firefox?
    >
    > This is not intended to be any sort of load tester just a url
    > validation and page check.
    >
    > Thanks in advance.
    > Greg.
    >
    Peter Tillotson, Jul 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Meena Lalwani
    Replies:
    1
    Views:
    1,126
    Kevin Spencer
    Aug 31, 2005
  2. s4189332

    Calculating average

    s4189332, Mar 18, 2009, in forum: Python
    Replies:
    0
    Views:
    255
    s4189332
    Mar 18, 2009
  3. Mike D

    calculating average from an array

    Mike D, Nov 19, 2004, in forum: ASP General
    Replies:
    3
    Views:
    118
    dlbjr
    Nov 19, 2004
  4. Jayesh Kamdar
    Replies:
    2
    Views:
    154
    Gunnar Hjalmarsson
    May 25, 2005
  5. Washington Ratso
    Replies:
    1
    Views:
    59
    Chris “Kwpolska†Warrick
    Apr 3, 2014
Loading...

Share This Page