Skip to content

Instantly share code, notes, and snippets.

@selfboot
Created June 27, 2016 09:15
Show Gist options
  • Select an option

  • Save selfboot/0b166f48c959893f2ebab2d345bec6c4 to your computer and use it in GitHub Desktop.

Select an option

Save selfboot/0b166f48c959893f2ebab2d345bec6c4 to your computer and use it in GitHub Desktop.
Simple website speed test tools.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @Last Modified time: 2016-06-27 17:03:42
import requests
import os
def get_speed_test(src_path, result_path, timeout=10):
all_sites = _get_sites_(src_path)
results = []
for site in all_sites:
print "Test site: {:s}".format(site)
try:
t = requests.get(site, timeout=timeout).elapsed.total_seconds()
except:
t = 9999
results.append(t)
print "Speed test finished! Write results to %s" % result_path
with open(result_path, 'w') as f:
map(lambda x: f.write("{:<30s} - {:2.5f}\n".format(x[0], x[1])), zip(all_sites, results))
def _get_sites_(file_path):
if not os.path.isfile(file_path):
return None
sites = []
with open(file_path, 'r') as f:
for site in f.readlines():
sites.append(site.strip())
return sites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment