Created
October 1, 2021 16:50
-
-
Save acu192/7697ead59fc34a017043a1e13b9e6703 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 sys | |
import time | |
import requests | |
from threading import Thread | |
URL = 'http://localhost:8003/api/temp/sleep' | |
def get(): | |
req = requests.get(URL) | |
res = req.json() | |
assert res['success'] | |
return res | |
def main(n): | |
begin = time.time() | |
threads = [Thread(target=get) for _ in range(n)] | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
end = time.time() | |
print(f'Took: {end - begin:.2} seconds') | |
if __name__ == '__main__': | |
main(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment