0

I'm trying to test the speed of my servers, and compare it with third parties' servers including Facebook, Tumblr and Google. I need to build a report with at least 100's of requests and I decided to do this with Python.

The idea is that I upload an image to Facebook, then re-download it (as Facebook modifies the image I upload) and upload it to the other third party servers as well as my own. I request the file x times for each server, and Python will print the time the request took each time.

Here is my script:

from time import time
from urllib import urlopen

# vars
url = raw_input("Please enter the URL you want to test: ")

for i in range(0,100):
    start_time = time()
    pic = urlopen(url)

    if pic.getcode() == 200:
        delta_time = time() - start_time
        print "%d" % (delta_time * 100)
    else:
        print "error"
print "%d requests made. File size: %d B" % (i, len(pic.read()))

I'm not great at Python so I'm not sure if I'm doing this right.

Is this the best way to do this?

1
  • 2
    If the code works the way it should, then, strictly speaking, the question is a little off-topic here; there's a site called Code Review where you can post working code for review. Commented Aug 27, 2012 at 19:25

2 Answers 2

1

There are scores of HTTP performance testing tools available. I would suggest you try one of those before creating your own.

Sign up to request clarification or add additional context in comments.

3 Comments

Such as 'ab' (Apache Benchmarking tool): httpd.apache.org/docs/2.2/programs/ab.html
Can I use this to test third party servers? I need to compare my download times to that of Facebook, Tumblr, Google, etc
If you go and hammer someone else's server, they might consider it a DoS attack and blacklist you, or take legal action. Besides, your server will never be faster than your internet connection. And I suspect Google and Facebook can afford a bigger "pipe" than most of us.
0

As pointed out by Lev Levitsky, this question actually belongs over at Code Review. The code I originally posted as intended, all I'm looking for is guidance on how to improve it.

Here is this question on Code Review.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.