Skip to content

Instantly share code, notes, and snippets.

@eduardoklosowski
Created July 8, 2022 11:37
Show Gist options
  • Save eduardoklosowski/79b90f48b7a939b67d0346d65fb6b6eb to your computer and use it in GitHub Desktop.
Save eduardoklosowski/79b90f48b7a939b67d0346d65fb6b6eb to your computer and use it in GitHub Desktop.
Comparação dos loops do asyncio e do uvloop no cPython 3.10 e PyPy 3.9-7.3.9
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
python loop tempo memoria
3.10 aio 13.55 15904
3.10 uv 5.59 17896
pypy aio 1.96 85300
3.10 aio 13.88 15980
3.10 uv 5.57 17968
pypy aio 1.96 85600
3.10 aio 13.86 16184
3.10 uv 5.68 18124
pypy aio 1.95 85584
3.10 aio 13.69 16156
3.10 uv 5.59 17900
pypy aio 1.97 85184
3.10 aio 13.68 16216
3.10 uv 5.63 17992
pypy aio 1.96 85604
3.10 aio 13.66 16120
3.10 uv 5.79 18136
pypy aio 1.94 85616
3.10 aio 13.80 16004
3.10 uv 5.76 18016
pypy aio 1.96 85604
3.10 aio 13.82 16056
3.10 uv 5.88 18036
pypy aio 1.94 85728
3.10 aio 13.49 15980
3.10 uv 5.85 17960
pypy aio 1.94 85976
3.10 aio 13.62 16188
3.10 uv 5.88 17944
pypy aio 1.94 85616
3.10 aio 14.01 16028
3.10 uv 5.79 18072
pypy aio 1.95 85336
3.10 aio 13.66 16176
3.10 uv 5.79 17968
pypy aio 1.95 85432
3.10 aio 13.72 15940
3.10 uv 5.82 18120
pypy aio 1.94 85336
3.10 aio 13.55 16100
3.10 uv 5.90 17972
pypy aio 2.01 85288
3.10 aio 13.70 16080
3.10 uv 5.88 18028
pypy aio 1.95 85380
3.10 aio 13.27 15980
3.10 uv 5.98 17924
pypy aio 1.96 85604
3.10 aio 13.30 16120
3.10 uv 5.74 17956
pypy aio 1.94 85844
3.10 aio 13.63 16116
3.10 uv 5.93 17952
pypy aio 1.93 85736
3.10 aio 13.28 15892
3.10 uv 5.99 18184
pypy aio 1.97 85840
3.10 aio 13.69 16024
3.10 uv 5.74 17952
pypy aio 1.93 85340
3.10 aio 13.75 15980
3.10 uv 5.73 17952
pypy aio 2.01 84892
3.10 aio 13.80 16076
3.10 uv 5.82 18040
pypy aio 1.95 85132
3.10 aio 13.62 16044
3.10 uv 5.72 17924
pypy aio 1.93 85332
3.10 aio 14.01 16076
3.10 uv 5.75 17944
pypy aio 1.95 85560
3.10 aio 13.29 15988
3.10 uv 5.79 18036
pypy aio 1.95 85656
import asyncio
async def funcao(iteracoes):
a = 0
for _ in range(iteracoes):
a += await asyncio.sleep(0, result=2)
return a
async def main(numero_tasks, iteracoes):
tasks = [asyncio.create_task(funcao(iteracoes)) for _ in range(numero_tasks)]
for task in tasks:
await task
if __name__ == '__main__':
import sys
if sys.argv[1] == 'uvloop':
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
asyncio.run(main(10, 500_000))
#!/bin/bash
EXECUCOES=25
(
echo 'python,loop,tempo,memoria'
for e in $(seq 1 "$EXECUCOES"); do
for p in cpython pypy; do
for l in asyncio uvloop; do
if [ "$p" = "pypy" ] && [ "$l" = "uvloop" ]; then
continue
fi
/usr/bin/time -f "$p,$l,%e,%M" ./env-"$p"/bin/python programa.py "$l"
done
done
done
) |& tee dados.csv
gzip -9 dados.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment