Skip to content

Instantly share code, notes, and snippets.

@Endi1
Created March 27, 2019 11:28
Show Gist options
  • Save Endi1/cd172b6c51ad6ce303e0cfc4749738b0 to your computer and use it in GitHub Desktop.
Save Endi1/cd172b6c51ad6ce303e0cfc4749738b0 to your computer and use it in GitHub Desktop.
import requests
sites = [
'http://www.google.com',
'http://www.youtube.com',
'http://www.polimi.it',
'http://wikipedia.org',
'http://www.amazon.it',
'http://www.twitter.com'
]
def find_average(request_times):
return sum(request_times) / len(request_times)
def get_url_times(url):
times = []
for request in range(10):
r = requests.get(url)
times.append(r.elapsed.microseconds/1000)
return times
def main():
min_avg = 0
current_min_url = ''
for url in sites:
times = get_url_times(url)
avg = find_average(times)
if min_avg == 0:
min_avg = avg
current_min_url = url
elif avg < min_avg:
min_avg = avg
current_min_url = url
print(current_min_url)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment