2023-06-27 17:58:12 +02:00
|
|
|
import datetime as dtt
|
|
|
|
import structio
|
|
|
|
|
|
|
|
|
|
|
|
async def task():
|
|
|
|
for i in range(100):
|
|
|
|
await structio.sleep(0.01)
|
|
|
|
|
|
|
|
|
|
|
|
async def main(tests: list[int]):
|
|
|
|
print("[main] Starting stress test, aggregate results will be printed at the end")
|
|
|
|
results = []
|
|
|
|
for N in tests:
|
|
|
|
print(f"[main] Starting test with {N} tasks")
|
|
|
|
start = dtt.datetime.utcnow()
|
|
|
|
async with structio.create_pool() as p:
|
|
|
|
for _ in range(N):
|
|
|
|
p.spawn(task)
|
|
|
|
end = dtt.datetime.utcnow()
|
|
|
|
results.append((end - start).total_seconds())
|
|
|
|
print(f"[main] Test with {N} tasks completed in {results[-1]:.2f} seconds")
|
2023-06-28 14:33:50 +02:00
|
|
|
results = " ".join(
|
|
|
|
(f"\n\t- {tests[i]} tasks: {r:.2f}" for i, r in enumerate(results))
|
|
|
|
)
|
2023-06-28 14:16:01 +02:00
|
|
|
print(f"[main] Results (values are in seconds): {results}")
|
2023-06-27 17:58:12 +02:00
|
|
|
|
|
|
|
|
2023-06-28 14:16:01 +02:00
|
|
|
structio.run(main, [10, 100, 1000, 10_000])
|