diff --git a/arequest.py b/arequest.py new file mode 100644 index 0000000..ce3f2e9 --- /dev/null +++ b/arequest.py @@ -0,0 +1,28 @@ +from time import perf_counter +import asyncio + +import aiohttp + + +async def fetch(s, url): + async with s.get("http://localhost:8000") as r: + return await r.text() + +async def fetch_all(s, urls): + tasks = [] + for url in urls: + task = asyncio.create_task(fetch(s, url)) + tasks.append(task) + return await asyncio.gather(*tasks) + +async def main(): + urls = range(1, 10 * 1000) + async with aiohttp.ClientSession() as s: + html = await fetch_all(s, urls) + print(html) + +if __name__ == "__main__": + start = perf_counter() + asyncio.run(main()) + end = perf_counter() + print(f"time: {end-start}")