timing a web response using urllib.urlopen??

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Wed Dec 31 18:17:11 CET 2003


MCollins at seminolecountyfl.gov:
>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.

class timer:
    def __init__(self,name,level=0,parms=""):
        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




More information about the Python-list mailing list