timing a web response using urllib.urlopen??

M

MCollins

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
 
R

Rene Pijlman

(e-mail address removed):
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;
 
C

Cousin Stanley

| 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.python
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.com' ,
'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.py

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top