Created
October 5, 2017 00:59
-
-
Save wmarshall484/b930b7eea0842dbc462d6d3ceeb93622 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 time | |
| import requests | |
| import threading | |
| class HTTPBencher(threading.Thread): | |
| def __init__(self, span): | |
| super(HTTPBencher, self).__init__() | |
| self.span=span | |
| self.final_count = None | |
| def run(self): | |
| start = time.time() | |
| count = 0 | |
| while time.time() - start < self.span: | |
| res = requests.get("http://127.0.0.1:80") | |
| count += 1 | |
| self.final_count = count | |
| span = 5 | |
| threads = 5 | |
| tds = [HTTPBencher(span) for x in range(threads)] | |
| for td in tds: | |
| td.start() | |
| total_count = 0 | |
| for td in tds: | |
| td.join() | |
| counts = [td.final_count for td in tds] | |
| print(sum(counts)/span) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment