Velocity Reviews > Calculating average time

# Calculating average time

GregM
Guest
Posts: n/a

 07-07-2005
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
ie = IEC.IEController()
start = datetime.datetime.today()
# asctime() returns a human readable time stamp whereas time() doesn't
startTimeStr = time.asctime()
start = datetime.datetime.today()
end = datetime.datetime.today()
pagetext = ie.GetDocumentText()
#check the returned web page for some things
if not (re.search(searchterm, pagetext):
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.

Greg.

Skip Montanaro
Guest
Posts: n/a

 07-07-2005

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
t = time.time()
cumulative += time.time() - t
n += 1

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

Skip

GregM
Guest
Posts: n/a

 07-07-2005
Thanks Skip. As usual I want to make it harder then it actually is.

Peter Tillotson
Guest
Posts: n/a

 07-08-2005
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 = []
> totalNumberTests = len(links)
> ie = IEC.IEController()
> start = datetime.datetime.today()
> # asctime() returns a human readable time stamp whereas time() doesn't
> startTimeStr = time.asctime()
> start = datetime.datetime.today()
> end = datetime.datetime.today()
> pagetext = ie.GetDocumentText()
> #check the returned web page for some things
> if not (re.search(searchterm, pagetext):
> 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.
>