Skip to content

Instantly share code, notes, and snippets.

@wmarshall484
Created October 5, 2017 00:59
Show Gist options
  • Select an option

  • Save wmarshall484/b930b7eea0842dbc462d6d3ceeb93622 to your computer and use it in GitHub Desktop.

Select an option

Save wmarshall484/b930b7eea0842dbc462d6d3ceeb93622 to your computer and use it in GitHub Desktop.
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