-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsh-http-benchmark.py
More file actions
31 lines (26 loc) · 937 Bytes
/
sh-http-benchmark.py
File metadata and controls
31 lines (26 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import sys
import time
import urllib.parse
import socket
import requests
def check_url(url, dns_separately=False):
if dns_separately:
bits = urllib.parse.urlparse(url)
ip = socket.gethostbyname(bits.netloc)
url = bits._replace(netloc=ip).geturl()
print("Checking %s" % url)
start = time.perf_counter()
resp = requests.get(url, allow_redirects=False)
resp.raise_for_status()
size = len(resp.text) # just to make sure we drained the response body
end = time.perf_counter()
duration = end - start
print("Fetched %s in %.1f seconds" % (size, duration))
def main():
seahorse_host = sys.argv[1]
for url_template in ["http://%s", "http://%s/Seahorse/JavaScript/UiText?ck=1234", "http://%s/Seahorse/JavaScript/UiTextCached?ck=1234&languageCode=en-US"]:
check_url(url_template % seahorse_host)
check_url(url_template % seahorse_host, True)
if __name__ == '__main__':
main()