Skip to content

Instantly share code, notes, and snippets.

@alphamarket
Created November 10, 2019 05:49
Show Gist options
  • Save alphamarket/6e2aba3b1f686e5a6accac7539b11daf to your computer and use it in GitHub Desktop.
Save alphamarket/6e2aba3b1f686e5a6accac7539b11daf to your computer and use it in GitHub Desktop.
Compute average download time of webpages
#!/usr/bin/python -u
from os import popen
import commands, sys
times = []
for x in xrange(int(sys.argv[1])):
status, output = commands.getstatusoutput("curl -so /dev/null %s -w %%{time_starttransfer}" %sys.argv[2])
if(status == 0):
times.append(float(output))
print "\r[%.1f%%] Average dowload time: %.2fs" %((x + 1) * 100 / float(sys.argv[1]), sum(times) / len(times)),
print ""
# $ python avg-download-time.py 7 https://www.google.com
# Going to curl `https://www.google.com` 7 times to compute average download time.
# [100.0%] Average download time: 0.98s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment