timing a web response using urllib.urlopen??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MCollins@seminolecountyfl.gov

    timing a web response using urllib.urlopen??

    hi all,

    python newbie alert! i'm trying to open an array of websites, timing each
    site's response time (how may seconds until a response)

    if someone could point me in the right direction on accomplishing the
    timer part of the this application, i'd appreciate it.

    thanks in advance


  • Rene Pijlman

    #2
    Re: timing a web response using urllib.urlopen? ?

    MCollins@semino lecountyfl.gov:[color=blue]
    >i'm trying to open an array of websites, timing each
    >site's response time (how may seconds until a response)
    >
    >if someone could point me in the right direction on accomplishing the
    >timer part of the this application, i'd appreciate it.[/color]

    class timer:
    def __init__(self,n ame,level=0,par ms=""):
    self.name = name
    self.parms = parms
    self.starttime = time.time()

    def report(self):
    elapsed = time.time() - self.starttime
    timefile = open("your filename here", 'a')
    print >>timefile, "%s\t%f\t%s " % (self.name, \
    elapsed, self.parms)
    timefile.close( )

    timer = new timer("eggs")
    # Do something that takes time
    timer.report()

    name: in my case identified the database query that was executed
    repeatedly.
    parms: the parameters of a particular execution of the query.

    I imported the output in a PostgreSQL database table to query the data.

    create table timer(
    name varchar,
    elapsed float,
    parms varchar
    );

    \copy timer from 'timefile.txt'

    select name, count(elapsed), sum(elapsed)
    from timer
    group by name
    order by sum(elapsed) desc;

    --
    René Pijlman

    Comment

    • Rene Pijlman

      #3
      Re: timing a web response using urllib.urlopen? ?

      Rene Pijlman:[color=blue]
      > self.starttime = time.time()[/color]

      This requires

      import time

      of course.

      --
      René Pijlman

      Comment

      • Cousin Stanley

        #4
        Re: timing a web response using urllib.urlopen? ?

        | i'm trying to open an array of websites,
        | timing each site's response time
        | ( how may seconds until a response )
        |
        | if someone could point me in the right direction
        | on accomplishing the timer part of the this application,
        | i'd appreciate it.

        '''
        NewsGroup .... comp.lang.pytho n
        Date ......... 2003-04-30
        Posted_By .... kkennedy
        Edited_By .... Stanley C. Kitching
        '''

        from urllib import urlopen

        import sys
        import time

        print '\n ' , sys.argv[ 0 ] , '\n'

        list_urls = [ 'http://www.python.org' ,
        'http://www.ibm.com' ,
        'http://www.microsoft.c om' ,
        'http://www.sun.com' , ]

        for this_url in list_urls :

        start = time.time()

        doc = urlopen( this_url ).read()

        end = time.time()

        print " %0.2f .... %s" % ( end - start , this_url )

        #
        # ------------------------------------------------------------
        #
        # Output ....
        #
        url_open_test.p y

        2.64 .... http://www.python.org
        1.10 .... http://www.ibm.com
        0.71 .... http://www.microsoft.com
        0.66 .... http://www.sun.com

        --
        Cousin Stanley
        Human Being
        Phoenix, Arizona

        Comment

        Working...