Calculating average time

G

GregM

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.
 
S

Skip Montanaro

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
 

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

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top