Skip to content

Instantly share code, notes, and snippets.

@vanne02135
Created March 3, 2010 21:25
Show Gist options
  • Save vanne02135/321050 to your computer and use it in GitHub Desktop.
Save vanne02135/321050 to your computer and use it in GitHub Desktop.
Simple speed test to check if local virtual box squid installation helps boosting the download speed from Flickr
import time
import urllib
import sys
__author__="vanne"
__date__ ="$3.3.2010 22:18:10$"
class ProxyTest:
# 192.168.11.5 is a virtual box running ubuntu and squid
proxies = {'http': 'http://192.168.11.5:3128'}
testurl = "http://farm3.static.flickr.com/2739/4358723026_84d9045990_o.jpg";
def __init__(self):
pass
def with_proxy(self):
t1 = time.clock()
filehandle = urllib.urlopen(ProxyTest.testurl, proxies=ProxyTest.proxies)
data = filehandle.read()
t2 = time.clock()
return len(data)/(t2-t1)
def without_proxy(self):
t1 = time.clock()
filehandle = urllib.urlopen(ProxyTest.testurl, proxies={})
data = filehandle.read()
t2 = time.clock()
return len(data)/(t2-t1)
def with_wrong_proxy(self):
t1 = time.clock()
filehandle = urllib.urlopen(ProxyTest.testurl, proxies={'http': 'http://this.does.not.exi.st:3128'})
data = filehandle.read()
t2 = time.clock()
return t2-t1
def check_data(self):
filehandle = urllib.urlopen(ProxyTest.testurl, proxies={})
data1 = filehandle.read()
filehandle = urllib.urlopen(ProxyTest.testurl, proxies=ProxyTest.proxies)
data2 = filehandle.read()
return data1 == data2
if __name__ == "__main__":
N = 4
pt = ProxyTest()
if pt.check_data():
print "Proxied and raw data match"
else:
print "!!! ERROR !!! proxied and raw data don't match"
no_proxy = []
for k in xrange(N):
no_proxy.append(pt.without_proxy())
sys.stdout.write(".")
sys.stdout.flush()
has_proxy = []
for k in xrange(N):
has_proxy.append(pt.with_proxy())
print ""
print "no proxy (b/s) " + str(no_proxy)
print "with proxy (b/s) " + str(has_proxy)
print "no proxy mean (kb/s) " + str(sum(no_proxy) / (N*1000))
print "with proxy mean (kb/s) " + str(sum(has_proxy) / (N*1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment