4 ms·
Out of curiosity, I checked if using uvloop[0] in Python changed the numbers. This is the code: # /// script # requires-python = ">=3.12" # dependencies
by polyrand 2y ago
Out of curiosity, I checked if using uvloop[0] in Python changed the numbers.
This is the code:
# /// script
# requires-python = ">=3.12"
# dependencies = ["uvloop"]
# ///
import asyncio
import sys
import uvloop
async def main(num_tasks):
tasks = []
for task_id in range(num_tasks):
tasks.append(asyncio.sleep(10))
await asyncio.gather(*tasks)
if __name__ == "__main__":
num_tasks = int(sys.argv[1])
# uvloop.run(main(num_tasks))
asyncio.run(main(num_tasks))
I ran it with 100k tasks:
/usr/bin/time -l -p -h uv run async-memory.py 100000
On my M1 MacBook Pro, using asyncio reports (~170MB):
170835968 maximum resident set size
Using uvloop (~204MB):
204259328 maximum resident set size
I kept the `import uvloop` statement when just using asyncio so that both cases start in the same conditions.
[0]: https://github.com/MagicStack/uvloop/ https://github.com/MagicStack/uvloop/