Last active
December 16, 2015 22:39
-
-
Save ahume/5508371 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import math | |
import sys | |
import socket | |
repeat = 10 | |
url = 'http://m.guardian.co.uk' | |
ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3' | |
if len(sys.argv) > 1 and sys.argv[1] > 0: | |
repeat = int(sys.argv[1]) | |
if len(sys.argv) > 2: | |
url = sys.argv[2] | |
print 'Getting %s response times' % repeat | |
print '--------------------------' | |
t = timeit.Timer("h.request('%s',headers={'cache-control':'no-cache', 'User-Agent': '%s'})" % (url, ua),"from httplib2 import Http; h=Http()") | |
times = t.repeat(repeat,1) | |
times.sort() | |
agg = reduce(lambda a,b: a+b, times) / len(times) | |
print 'Average: %ss' % agg | |
med = times[len(times)/2] | |
print ' 50%%: %ss' % med | |
nth = times[int(math.floor(len(times) * 0.6))] | |
print ' 60%%: %ss' % nth | |
nth = times[int(math.floor(len(times) * 0.7))] | |
print ' 70%%: %ss' % nth | |
nth = times[int(math.floor(len(times) * 0.8))] | |
print ' 80%%: %ss' % nth | |
nth = times[int(math.floor(len(times) * 0.9))] | |
print ' 90%%: %ss' % nth | |
nth = times[len(times) - 1] | |
print ' 100%%: %ss' % nth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment