From 1a32e6c05fe6b4403e8816e90ee8cc903e78c42e Mon Sep 17 00:00:00 2001 From: Askill Date: Sat, 23 Apr 2022 21:08:21 +0200 Subject: [PATCH] plot hsit of wait times --- clients.py | 14 +++++++++++--- requirements.txt | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clients.py b/clients.py index 79523f8..77bb29a 100644 --- a/clients.py +++ b/clients.py @@ -3,21 +3,29 @@ import asyncio import time import websockets +import matplotlib.pyplot as plt +import numpy as np + async def hello(x, string): + t1 = time.time() + num = 500 async with websockets.connect("ws://localhost:8765") as websocket: - for _ in range(100): + for _ in range(num): await websocket.send(string) await websocket.recv() + return (time.time() - t1) / num async def main(x): string = "Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It’s not a story the Jedi would tell you. It’s a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life… He had such a knowledge of the dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful… the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself." string2 = "Hi" coros = [hello(i, string) for i in range(x)] - await asyncio.gather(*coros) + times = await asyncio.gather(*coros) + plt.hist(times, density=True, bins=20) + plt.show() if __name__ == '__main__': - for i in range(7000, 12000, 100): + for i in range(100, 12000, 100): t1 = time.time() loop = asyncio.get_event_loop() loop.run_until_complete(main(i)) diff --git a/requirements.txt b/requirements.txt index 7a38911..d5fb6a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -websockets \ No newline at end of file +websockets +numpy +matplotlib \ No newline at end of file