{ "cells": [ { "cell_type": "markdown", "id": "56841af7", "metadata": {}, "source": [ "Instrumentation of code often results in what is known as the 'probing' effect. Collecting data about function runtime with instrumentation, as Yappi does, may cause the profiled code to not run correctly or run more slowly, distorting the measured results. The SCALENE paper shows that sampling-based profilers are capable of outperforming instrumentation in this regard.\n", "\n", "Yappi fully supports asyncio, while no sampling based profiler does so far. This is where the prototype profiler Aergia comes in---it has basic support for all sort of programs, but really prioritizes assigning time to suspended asyncio tasks, allowing developers insight into the efficiency of their event loop.\n", "\n", "This notebook attempts to demonstrate that Aergia is comparable to Yappi, while also avoiding the probe effect characteristic of deterministic profilers." ] }, { "cell_type": "code", "execution_count": 1, "id": "054eab59", "metadata": {}, "outputs": [], "source": [ "import sys\n", "import asyncio" ] }, { "cell_type": "markdown", "id": "317ba5a2", "metadata": {}, "source": [ "Adding the Aergia folder to my modules path is required:" ] }, { "cell_type": "code", "execution_count": 2, "id": "33fb8e3a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['/gnu/store/c5qarpvwzcz1idryvvpiqd7738jn4rs1-python-3.11.11/lib/python311.zip', '/gnu/store/c5qarpvwzcz1idryvvpiqd7738jn4rs1-python-3.11.11/lib/python3.11', '/gnu/store/c5qarpvwzcz1idryvvpiqd7738jn4rs1-python-3.11.11/lib/python3.11/lib-dynload', '', '/home/bdunahu/.local/lib/python3.11/site-packages', '/gnu/store/8gcczykad73pbymiz28w594gqc2mcm7g-python-notebook-6.5.7/lib/python3.11/site-packages', '/gnu/store/x8l5b47rka6ydfh0vfscr3i8gxw781zc-python-coverage-7.6.8/lib/python3.11/site-packages', '/gnu/store/dkkdj4k885l3sy6m12p0yf07r1hb5csp-python-jupyter-server-2.14.0/lib/python3.11/site-packages', '/gnu/store/9wv3kgs4xc3zvcki9sblqr42pdcxnf39-python-nbval-0.11.0/lib/python3.11/site-packages', '/gnu/store/ihha82cm6xh1g7692k8wlf7fcp24j0kv-python-pytest-8.3.3/lib/python3.11/site-packages', '/gnu/store/21qdhfn1s445ci3jmpr1dbc8kpjhzhci-python-pytest-cov-6.0.0/lib/python3.11/site-packages', '/gnu/store/mryfl1mwhyf1lri6km6y27c2kb1x4y3p-python-requests-2.31.0/lib/python3.11/site-packages', '/gnu/store/21gj6vmih8113hp07dnkxf53r8gz3kf8-python-requests-unixsocket2-0.4.2/lib/python3.11/site-packages', '/gnu/store/d7c41kl3qkynmiwcyj26fppwckifd3hq-python-setuptools-67.6.1/lib/python3.11/site-packages', '/gnu/store/8af8k4p93zahcfndz160m20bfrlf5h4l-python-wheel-0.40.0/lib/python3.11/site-packages', '/gnu/store/ycqwsapbkpmwnfinfdfyc30jsadp6drc-python-argon2-cffi-21.1.0/lib/python3.11/site-packages', '/gnu/store/0wx7mmnfb3dpsfkzfkhh9iflvjd8ihsg-python-ipykernel-6.29.4/lib/python3.11/site-packages', '/gnu/store/z9yyzbh2kfd19yysnk7iyhasfs8wgwi2-python-ipython-genutils-0.1.0/lib/python3.11/site-packages', '/gnu/store/bk2bgyy9nwl5x55dvfsfysi34l2jwwf5-python-jinja2-3.1.2/lib/python3.11/site-packages', '/gnu/store/bjfa91d5z29ygdx7w7bmz4969b0lfqkv-python-jupyter-client-7.4.4/lib/python3.11/site-packages', '/gnu/store/z9s2jvw8fb598s9brpm0wqgy6svxb691-python-jupyter-core-5.7.2/lib/python3.11/site-packages', '/gnu/store/gwbjk09d3g7lw636zk8dfvlfkyisrrzp-python-nest-asyncio-1.5.5/lib/python3.11/site-packages', '/gnu/store/anryryjr4p9pazpcb8aw82dby9dps3fi-python-nbclassic-1.0.0/lib/python3.11/site-packages', '/gnu/store/iji0b84gi65aaagypg06ah1cdqiwdsii-python-nbconvert-7.16.4/lib/python3.11/site-packages', '/gnu/store/akc5pxyrd4z14yvf00ys5aqb7hqpja2x-python-nbformat-5.10.4/lib/python3.11/site-packages', '/gnu/store/pi5bvn8iyv098ap6nx50j3sgkwcy43m4-python-prometheus-client-0.20.0/lib/python3.11/site-packages', '/gnu/store/vy0dc7a2fm7ry9y4dcmfhc9wdpd5zi8y-python-pyzmq-25.1.0/lib/python3.11/site-packages', '/gnu/store/h2517sx6jg6a3vvkrmvm2v9b4q1x6lkw-python-send2trash-1.8.2/lib/python3.11/site-packages', '/gnu/store/7m1wxcm5ly0lg1jj099ggw7jfs3sfc46-python-terminado-0.10.0/lib/python3.11/site-packages', '/gnu/store/simm56r07r2g6hc4qkz8vvp4zdwc51ps-python-tornado-6.4.2/lib/python3.11/site-packages', '/gnu/store/4aq408ifx2sc8d4ijs3ibkvac3f69y2p-python-traitlets-5.14.1/lib/python3.11/site-packages', '/gnu/store/3nnkbl90qk9l7a757ldxjdxyz73p0b9c-python-3.11.11/lib/python3.11/site-packages', '/gnu/store/50w8avb4mdmfqddpkjydiiv95v3xjds5-python-tomli-2.1.0/lib/python3.11/site-packages', '/gnu/store/g8ycyd5jvjw6g2h3sppj2ac2y86kyhbg-python-websocket-client-1.8.0/lib/python3.11/site-packages', '/gnu/store/0m54sa414acswx0i119dnim4hsdamcnx-python-packaging-24.2/lib/python3.11/site-packages', '/gnu/store/r95sk8cjyz7w40dhl1qdcqvfdm41d6mf-python-overrides-7.7.0/lib/python3.11/site-packages', '/gnu/store/npszb6i1683ya9idsgdcjibkxxpjzsnj-python-jupyter-server-terminals-0.5.3/lib/python3.11/site-packages', '/gnu/store/drszs8dx74zm0nr7xvfkvmsa568fh028-python-jupyter-events-0.10.0/lib/python3.11/site-packages', '/gnu/store/2g266m4i3mcjma0l7b51qsrvw4y9gkvy-python-anyio-4.6.2/lib/python3.11/site-packages', '/gnu/store/j3vk0v15cvmn3qvgm4mpyxik82h0rdlr-python-six-1.16.0/lib/python3.11/site-packages', '/gnu/store/l7mf7i7r2w18xsb2b3r6gk2674nn4a7m-python-py-1.11.0/lib/python3.11/site-packages', '/gnu/store/m7yld8jfs03s5dhlgp292p7ifwp43j17-python-pluggy-1.5.0/lib/python3.11/site-packages', '/gnu/store/djlwr8zkx7bmviypfbh7nwkg57ysdmp6-python-exceptiongroup-1.1.1/lib/python3.11/site-packages', '/gnu/store/3xlb5f0cvhrl2202frr3hqavfdjwdzx4-python-packaging-bootstrap-24.2/lib/python3.11/site-packages', '/gnu/store/cqw0fmfhyqxlvyizv2cqc5y3qh1ywa9s-python-iniconfig-1.1.1/lib/python3.11/site-packages', '/gnu/store/1d7kn9ldv5idlh3bb8a7yajryc8f3ppk-python-attrs-bootstrap-24.2.0/lib/python3.11/site-packages', '/gnu/store/fn9kh5z47nixnpdan1980ggndcp96zsh-python-urllib3-2.2.1/lib/python3.11/site-packages', '/gnu/store/1kmaa5nl0ih4nqbqcif8rgv17iq7dvms-python-idna-3.3/lib/python3.11/site-packages', '/gnu/store/2b7ry0xs541z0ibl9rf5h0jnzvn1pmd0-python-charset-normalizer-2.1.0/lib/python3.11/site-packages', '/gnu/store/vdvcyy897wjk6s39ji3rahaga7v8ki7h-python-certifi-2022.6.15/lib/python3.11/site-packages', '/gnu/store/j5lp5hkbcz7mqxgac1hgcm517bckb73b-python-pbr-5.5.1/lib/python3.11/site-packages', '/gnu/store/hpajypigh3iaq0zw6vcw1jdzmdq1j962-python-typing-extensions-4.12.2/lib/python3.11/site-packages', '/gnu/store/jm1r2v84pfp28njl3agxaj4nmnwpzjs0-python-cffi-1.17.1/lib/python3.11/site-packages', '/gnu/store/qmgmik8rc44f8v5d33smzg6cwgrbvip4-python-psutil-5.9.2/lib/python3.11/site-packages', '/gnu/store/yn165r281f7y7axx0wr8jc64gqkw28cf-python-matplotlib-inline-0.1.3/lib/python3.11/site-packages', '/gnu/store/1sr8ig20np4zxqx386ykpq0cg9b82zxy-python-ipython-8.29.0/lib/python3.11/site-packages', '/gnu/store/wawlwscyr7sza5s11h81y6iwvrwwkiqa-python-debugpy-1.8.9/lib/python3.11/site-packages', '/gnu/store/dx5wpfm0vyy4z7xv7dx3xqsvqwhkxpjq-python-comm-0.2.2/lib/python3.11/site-packages', '/gnu/store/yzhc3lsqn8gwjs5vyvxk551s0fkly664-python-markupsafe-2.1.1/lib/python3.11/site-packages', '/gnu/store/gjhl4ggs0m9hggna0xy47c03mc88f2rd-python-entrypoints-0.3/lib/python3.11/site-packages', '/gnu/store/fazc70c4gxqgk7fh0gyd4n8i9p3x2y56-python-dateutil-2.8.2/lib/python3.11/site-packages', '/gnu/store/1ii8v3vbzlxk9ngdrawmckscfa731rl4-python-platformdirs-4.3.6/lib/python3.11/site-packages', '/gnu/store/g3p96hgq4hhp5azr3xarcg5gamfscbqx-python-notebook-shim-0.2.4/lib/python3.11/site-packages', '/gnu/store/cxg3l0d9xdcxxj74ff4awmhk6ga3fywq-python-tinycss2-1.4.0/lib/python3.11/site-packages', '/gnu/store/fqf4najfm6yp6baml031f48dbvali63f-python-pygments-2.15.1/lib/python3.11/site-packages', '/gnu/store/k1aq0v4fhd4gv5q30kv6ivjn33rn2hv7-python-pandocfilters-1.5.0/lib/python3.11/site-packages', '/gnu/store/nnv9cqpcx27jymn7lvwnsg2gbvb3aynz-python-nbclient-0.10.0/lib/python3.11/site-packages', '/gnu/store/67pfbf7dkw8l7qy9gj9c2crw5kwwhk3y-python-mistune-3.0.2/lib/python3.11/site-packages', '/gnu/store/zkx6skh4zgnw69jfbdwv7038mhjar3wi-python-jupyterlab-pygments-0.1.2/lib/python3.11/site-packages', '/gnu/store/s3w3q7m4xgvvc1fycakcb2853i4vlgpp-python-importlib-metadata-5.2.0/lib/python3.11/site-packages', '/gnu/store/4wlr8i0ha615n6x2399d8nx3wi8nhfgs-python-defusedxml-0.7.1/lib/python3.11/site-packages', '/gnu/store/fva0pfjx8dpygg69cr1y4822x44ghckk-python-bleach-6.0.0/lib/python3.11/site-packages', '/gnu/store/28kii7vzz482p40pb24ympk2sfkpmj9n-python-beautifulsoup4-4.12.3/lib/python3.11/site-packages', '/gnu/store/8bl94jfrlzbfaar4why8prchscsjxv0w-python-jsonschema-4.23.0/lib/python3.11/site-packages', '/gnu/store/qbksi5islk7qz2v3wc85jxwx8znldybp-python-fastjsonschema-2.20.0/lib/python3.11/site-packages', '/gnu/store/0gjwdiaxwzzgyvd0z4mxhzg154bfsz33-python-ptyprocess-0.7.0/lib/python3.11/site-packages', '/gnu/store/7wgwzr1i93kyvy8i35lwm08ijics096l-python-pyparsing-3.2.1/lib/python3.11/site-packages', '/gnu/store/mn51ag3b29p9bvlm8w4208nqqvjcg96q-python-rfc3986-validator-0.1.1/lib/python3.11/site-packages', '/gnu/store/jlgp0fnl49gasgqhdzzj6a5a5f5pvgj2-python-rfc3339-validator-0.1.4/lib/python3.11/site-packages', '/gnu/store/6kkrn368ky8dmz7mciwfhvmaw12a6a9h-python-rich-13.7.1/lib/python3.11/site-packages', '/gnu/store/jvfidn54kx51qc9s2l3846w9w81zkrkj-python-referencing-0.35.1/lib/python3.11/site-packages', '/gnu/store/b79n68m9pa68rs07ngra1c3a9b3xi1qv-python-pyyaml-6.0.1/lib/python3.11/site-packages', '/gnu/store/c29z1izy27z0p0msq190csdm8i2as5l8-python-json-logger-2.0.7/lib/python3.11/site-packages', '/gnu/store/ys4rj84grbhahdmgvdyh6rzxkj74g39m-python-sniffio-1.3.1/lib/python3.11/site-packages', '/gnu/store/dvbnl28vw2fw0dlvhpg89hyj7l8ip2k8-python-contextvars-2.4/lib/python3.11/site-packages', '/gnu/store/iz01ddzyva0qf1iyrzdxaldprrd072pi-python-six-bootstrap-1.16.0/lib/python3.11/site-packages', '/gnu/store/diwaq9r0acrxiigwhjbrwhqlhyzlky4p-python-pysocks-1.7.1/lib/python3.11/site-packages', '/gnu/store/ll6g7b9vxzfy62gh3pa520b59fdzv1z4-python-pyopenssl-24.3.0/lib/python3.11/site-packages', '/gnu/store/vkd8q5q3snswznfra0k1ri2sawf3hn6r-python-cryptography-44.0.0/lib/python3.11/site-packages', '/gnu/store/7qbsfm3pzcc73cvqdj2755d8wkqhjmil-python-pycparser-2.21/lib/python3.11/site-packages', '/gnu/store/3w17ixn6p10dbqgkilz20m1g9najdl5v-python-matplotlib-3.8.2/lib/python3.11/site-packages', '/gnu/store/8c5cfz99zm85zkv8gms61w06xhzn9j97-python-stack-data-0.6.3/lib/python3.11/site-packages', '/gnu/store/wlgbwr1wxi0fn8kk4qj1j2yncwdgj8cq-python-prompt-toolkit-3.0.43/lib/python3.11/site-packages', '/gnu/store/sbcqdb38vqgvni2mpzn0df00nscn7ba7-python-pexpect-4.9.0/lib/python3.11/site-packages', '/gnu/store/c5dr3hm1nv43gpyh13z97fkb13sy35gm-python-jedi-0.19.2/lib/python3.11/site-packages', '/gnu/store/ky32ynvbqxwyqakwyk0hj2nl60ahi157-python-decorator-5.0.9/lib/python3.11/site-packages', '/gnu/store/sx5g7545dvffcai9wvmj1jd3vzk69nbn-python-colorama-0.4.6/lib/python3.11/site-packages', '/gnu/store/nl62s39bdjv0wpnk4az3b2mnm71a1xw3-python-pydevd-3.2.3/lib/python3.11/site-packages', '/gnu/store/3r4vfjk4d1w6q37s8kpj1jll45gjdhlb-python-webencodings-0.5.1/lib/python3.11/site-packages', '/gnu/store/i3sfl4fjan7f7ixg7rbm99wqvmbhdbjj-python-zipp-1.0.0/lib/python3.11/site-packages', '/gnu/store/f245zik0hby777kikcrcdfycd196dlb6-python-html5lib-1.1/lib/python3.11/site-packages', '/gnu/store/j7cxak4y2a62k2i8ikq0msy87rk1arsh-python-lxml-5.2.2/lib/python3.11/site-packages', '/gnu/store/r73gfkjy67zhyh8p2gpbr3x3b03nmr08-python-soupsieve-2.2.1/lib/python3.11/site-packages', '/gnu/store/pabwbhbx55jp0s1nq18ha5px0i1qc0d6-python-webcolors-24.11.1/lib/python3.11/site-packages', '/gnu/store/7sim1sl86wlzlzl64mia57vdg2g13dfx-python-uri-template-1.3.0/lib/python3.11/site-packages', '/gnu/store/ffqxhrsxgwk4mryc02wqwr7bd5mz8k7h-python-rpds-py-0.10.6/lib/python3.11/site-packages', '/gnu/store/jwm3g5rcsy3k6w4q6syk8w7kda9dajr8-python-referencing-bootstrap-0.35.1/lib/python3.11/site-packages', '/gnu/store/zm437l9b9i4l2v104sgkfqff3rkh2irj-python-jsonschema-specifications-2024.10.1/lib/python3.11/site-packages', '/gnu/store/gsw4ykif32dvi6qkp2gz9xvpjc0s81gc-python-jsonpointer-1.14/lib/python3.11/site-packages', '/gnu/store/7acqbdccam1kmbhj534zw4fqdspc948h-python-isoduration-20.11.0/lib/python3.11/site-packages', '/gnu/store/r54812jhf9ws0hxnmk54s0y1g1ri92m1-python-importlib-resources-5.12.0/lib/python3.11/site-packages', '/gnu/store/2mvwx9qjiwqxb6akzjiv6lz13ayg57a8-python-fqdn-1.5.1/lib/python3.11/site-packages', '/gnu/store/hkf1b0xdiwrxwfvs1a066fl4j8mzckfb-python-attrs-24.2.0/lib/python3.11/site-packages', '/gnu/store/7x182vymw0sdd1ym52mb3pw0rlxh52zv-python-markdown-it-py-3.0.0/lib/python3.11/site-packages', '/gnu/store/5jkb6p28qykp1g3pbg8pqkzcxxzakw7x-python-immutables-0.21/lib/python3.11/site-packages', '/gnu/store/yv4n6ng492crwj9nq6bn0kjpzrix7vjp-python-3.11.11-tk/lib/python3.11/site-packages', '/gnu/store/fzr0qvwglnyfkwkhp2awa6qyqc9iggla-python-pillow-11.1.0/lib/python3.11/site-packages', '/gnu/store/pf1jgr4zjq9ah69s3hrgcp36cxxaj0qj-python-numpy-1.26.4/lib/python3.11/site-packages', '/gnu/store/34y2dizg06p667xmjjcq47n84bimg74l-python-kiwisolver-1.4.6/lib/python3.11/site-packages', '/gnu/store/7r0bfbq1l90qsihhsqad4s5f3w63dhkv-python-fonttools-minimal-4.39.3/lib/python3.11/site-packages', '/gnu/store/6q1s56a6qnxh9b704b9y95jyxi15z3wy-python-cycler-0.10.0/lib/python3.11/site-packages', '/gnu/store/cnk6flgsd9b6g9mywg2w8j3fgnvdmcf6-python-contourpy-1.3.2/lib/python3.11/site-packages', '/gnu/store/v3dvpj36qih2p1ipvzf0dh4flswswhb4-python-pure-eval-0.2.3/lib/python3.11/site-packages', '/gnu/store/z855h6njq66g87vxxi25rblky0yxnwd5-python-executing-2.1.0/lib/python3.11/site-packages', '/gnu/store/9qx4gnv4hz9gpq7q4zzlkhks3nx0p5w2-python-asttokens-2.4.1/lib/python3.11/site-packages', '/gnu/store/z710c9ibc3fnvc6wqys9jdz0al8w9dh7-python-wcwidth-0.2.13/lib/python3.11/site-packages', '/gnu/store/8rjg30isj2f3l0x6ypdg4nj3j1vzb2b1-python-parso-0.8.4/lib/python3.11/site-packages', '/gnu/store/2d7jpdwjjs8sqwck7cal3sd5p3mxc716-python-more-itertools-10.6.0/lib/python3.11/site-packages', '/gnu/store/m0mbw0x6265ydqpksdfws5qiaj83vlci-python-chardet-5.2.0/lib/python3.11/site-packages', '/gnu/store/w0hl7d5867napkafsp85qz15xnswslgz-python-arrow-1.2.3/lib/python3.11/site-packages', '/gnu/store/izkankkiazd6b1xbi1sfshbv0yss7nxz-python-cached-property-2.0.1/lib/python3.11/site-packages', '/gnu/store/xl94l93pld8bxbpdcxhbd7z8jasn3mha-python-panflute-2.3.0/lib/python3.11/site-packages', '/gnu/store/9dvbnq602glhvrbk6lqbaxd4ifn8grvh-python-mistletoe-1.3.0/lib/python3.11/site-packages', '/gnu/store/li646794v86v1c6wlhvffv29l7qljwz8-python-mdurl-0.1.2/lib/python3.11/site-packages', '/gnu/store/fbb83fjfkqgjl66qjpm019ars526fj8w-python-markdown-3.3.4/lib/python3.11/site-packages', '/gnu/store/hnj9qg4ybrqd4rj406psf8mzc7rpiwn3-python-linkify-it-py-2.0.0/lib/python3.11/site-packages', '/gnu/store/y8caisgjifxa4aqpiaxdwjhy449f2l1p-python-commonmark-0.9.1/lib/python3.11/site-packages', '/gnu/store/vrsxnwwmbslhlv4500whcdg6wfkbqb53-python-click-8.1.7/lib/python3.11/site-packages', '/gnu/store/7h80aql8fkvlnq5ywwpvil5yjldfv40l-python-uc-micro-py-1.0.1/lib/python3.11/site-packages', '/gnu/store/9sscnmx9s0b66chv2nd3wc110fqmk01c-python-hatchling-1.26.1/lib/python3.11/site-packages', '/gnu/store/i11m2aa9nks0mxn4gdy6xk1bgsxa60n5-python-pip-23.1/lib/python3.11/site-packages', '/gnu/store/k3y3iq5vb5n9v05gpl4m5fnhf4nxnqix-python-pre-commit-3.7.1/lib/python3.11/site-packages', '/gnu/store/b26wqy976fxvpirwaanh1blnavhkj12q-python-pytest-timeout-2.3.1/lib/python3.11/site-packages', '/gnu/store/r3fyqnr3a4laq2hzlx1jvfgn2a0cnig6-python-trove-classifiers-2024.10.21.16/lib/python3.11/site-packages', '/gnu/store/5li4bcywi3r9vas9pny8r3s1clwiz3g1-python-pathspec-0.11.1/lib/python3.11/site-packages', '/gnu/store/ff3x2cl0linkxwi5nd073yl1r239m2wr-python-editables-0.5/lib/python3.11/site-packages', '/gnu/store/5ga8dlgfy41ksmmzlpala7c81xppd9f2-python-virtualenv-20.29.1/lib/python3.11/site-packages', '/gnu/store/lll8f9srw4qpkn8f1d8jjwmrbcd2jd72-python-nodeenv-1.8.0/lib/python3.11/site-packages', '/gnu/store/ar9fvhmbmdfyvnaa84mn0pr9qn05wr9y-python-identify-2.5.36/lib/python3.11/site-packages', '/gnu/store/8mdgjh6w4160ra15nmwgbins0k6by0mk-python-cfgv-3.4.0/lib/python3.11/site-packages', '/gnu/store/8md4l2hkn46b213sbkpxprin8aa2g03h-python-filelock-3.16.1/lib/python3.11/site-packages', '/gnu/store/fg0wxqdwvd86xa8cmbcqbiqa756lakff-python-distlib-0.3.7/lib/python3.11/site-packages', '/gnu/store/61sxpc8fx54qq7syhrfg444mx61gnyaa-python-editdistance-0.3.1-1.3ea84a7/lib/python3.11/site-packages', '/gnu/store/d4yk6bf542xnzh260zfcb5lmg2lcv0is-profile/lib/python3.11/site-packages', '/home/bdunahu/.guix-home/profile/lib/python3.11/site-packages', '/gnu/store/c5qarpvwzcz1idryvvpiqd7738jn4rs1-python-3.11.11/lib/python3.11/site-packages', '../aergia/']\n" ] } ], "source": [ "sys.path.append('../aergia/')\n", "print(sys.path)" ] }, { "cell_type": "code", "execution_count": 3, "id": "00b36557", "metadata": {}, "outputs": [], "source": [ "from aergia import Aergia\n", "import yappi" ] }, { "cell_type": "code", "execution_count": 4, "id": "3eb2281d", "metadata": {}, "outputs": [], "source": [ "?Aergia" ] }, { "cell_type": "markdown", "id": "ca110c31", "metadata": {}, "source": [ "# Yappi and Aergia" ] }, { "cell_type": "markdown", "id": "4aa51b85", "metadata": {}, "source": [ "Aergia reports profiling information on the line level like SCALENE, where yappi reports timing information on the function level.\n", "\n", "There are a couple other minor differences too:\n", "\n", "- yappi reports CPU time and wall time; Aergia only does wall time.\n", "- yappi reports information for every function (default), Aergia only reports the the suspended line in each task." ] }, { "cell_type": "markdown", "id": "aa685355", "metadata": {}, "source": [ "Since Yappi keeps track of all functions, I'll want our print statement to filter out only what I care about (stealing a function from Aergia):" ] }, { "cell_type": "code", "execution_count": 4, "id": "591908f7", "metadata": {}, "outputs": [], "source": [ "def yappi_print_traceable_results(stats):\n", " '''Filters the list of yappi stats, printing information for only the same\n", " functions as Aergia. This is for manual testing.'''\n", " print(f\"{'FILE':<30} {'FUNC':<30} {'SEC':<10}\")\n", " for s in stats:\n", " fname = s.module\n", " if Aergia._should_trace(fname):\n", " fname = \\\n", " (fname if len(fname) <= 25 else fname[-25:])\n", " print(f\"{fname}:{s.lineno}\".ljust(30) +\n", " f\"{s.name:<30} {s.ttot:<10.4f}\")" ] }, { "cell_type": "markdown", "id": "efd1804d", "metadata": {}, "source": [ "# Setting up yappi and Aergia" ] }, { "cell_type": "markdown", "id": "af4924a8", "metadata": {}, "source": [ "Yappi is a singleton class, which means it doesn't require much setup. However, it must be set to profile wallclock time rather than the default of cpu time, as it does not report await statements in virtual time." ] }, { "cell_type": "code", "execution_count": 5, "id": "1bd50c9e", "metadata": {}, "outputs": [], "source": [ "def reset_yappi():\n", " yappi.stop()\n", " yappi.clear_stats()\n", " yappi.set_clock_type('wall')\n", " yappi.set_context_id_callback(None)\n", " yappi.set_context_name_callback(None)\n", " yappi.set_tag_callback(None)" ] }, { "cell_type": "markdown", "id": "a48930f9", "metadata": {}, "source": [ "The rest is so I may reset the profiler inbetween executions. Aergia also requires this, and must be instantiated one time:" ] }, { "cell_type": "code", "execution_count": 6, "id": "ad7a7bd6", "metadata": {}, "outputs": [], "source": [ "aergia_interval = 0.01 # standard profiling interval\n", "profiles_everything = True\n", "aergia = Aergia(aergia_interval, profiles_everything)\n", "\n", "def reset_aergia():\n", " aergia.clear()" ] }, { "cell_type": "markdown", "id": "d50ff88f", "metadata": {}, "source": [ "I found that results are slightly more consistent when I run the event loop in a separate thread. Jupyter is running its own event loop on the main thread, which may cause extra delays.\n", "\n", "I'll further bundle this with the actual await call:" ] }, { "cell_type": "code", "execution_count": 7, "id": "2b8b09ae", "metadata": {}, "outputs": [], "source": [ "from threading import Thread" ] }, { "cell_type": "code", "execution_count": 8, "id": "f94e192d", "metadata": {}, "outputs": [], "source": [ "def run_coro(coro):\n", " thread = Thread(target=lambda: asyncio.run(coro))\n", " thread.start()\n", " thread.join()\n", "\n", "def run_with_yappi(coro, should_print=False):\n", " reset_yappi()\n", " yappi.start()\n", " run_coro(coro)\n", " yappi.stop()\n", " r = yappi.get_func_stats()\n", " if should_print:\n", " yappi_print_traceable_results(r)\n", " return r\n", "\n", " \n", "def run_with_aergia(coro, should_print=False):\n", " reset_aergia()\n", " aergia.start()\n", " run_coro(coro)\n", " if should_print:\n", " aergia.print_samples()\n", " r = aergia.get_samples()\n", " aergia.stop()\n", " return r" ] }, { "cell_type": "markdown", "id": "fd7812a6", "metadata": {}, "source": [ "# asyncio.sleep (sequential)" ] }, { "cell_type": "markdown", "id": "18401e85", "metadata": {}, "source": [ "The sleep function will allow me to compare yappi and aergia while minimizing non-determinism. Note that it, in fact, runs sequentially." ] }, { "cell_type": "code", "execution_count": 9, "id": "638bdada", "metadata": {}, "outputs": [], "source": [ "async def snooze():\n", " await asyncio.sleep(0.025)\n", "\n", "async def alarm(times):\n", " for i in range(times):\n", " await snooze()" ] }, { "cell_type": "code", "execution_count": 11, "id": "d30993d9", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FILE FUNC PERC (ACTUAL -> SEC)\n", "ernel_26033/1510412079.py:2 snooze 33.333% (63.000 -> 0.630000)\n", "kernel_26033/510785827.py:4 run_coro 33.333% (63.000 -> 0.630000)\n", "kernel_26033/510785827.py:2 33.333% (63.000 -> 0.630000)\n", "FILE FUNC SEC \n", "kernel_26033/510785827.py:1 run_coro 0.6444 \n", "kernel_26033/510785827.py:2 0.6422 \n", "ernel_26033/1510412079.py:4 alarm 0.6394 \n", "ernel_26033/1510412079.py:1 snooze 0.6393 \n" ] } ], "source": [ "run_with_aergia(alarm(25), True)\n", "run_with_yappi(alarm(25), True)\n", "None" ] }, { "cell_type": "markdown", "id": "436ab8d8", "metadata": {}, "source": [ "Note that when sampling, Aergia only assigns time to the current suspended task, so the `await snooze()` line does not have time attributed to it." ] }, { "cell_type": "markdown", "id": "1414a394", "metadata": {}, "source": [ "Also, remember how yappi has to run instrumented profiling code on every function exit and exit? Given the above `snooze` function contains no logic, calling it for a greater number of repetitions might accumulate the overhead." ] }, { "cell_type": "markdown", "id": "103e2dbc", "metadata": {}, "source": [ "To do this experiment, I'll first create a function that puts Aergia and yappi on more even footing: one to sum up all the time spent in the lines of a function under one number.\n", "\n", "I'll have to remember that this number can be misleading, percisely due to reporting inconsistences between the two profilers as shown above." ] }, { "cell_type": "code", "execution_count": 10, "id": "8a15b19b", "metadata": {}, "outputs": [], "source": [ "def yappi_extract_values_by_func(stats, func_name):\n", " '''Returns the total number of samples for function name, given a\n", " yappi stats object.'''\n", " for s in stats:\n", " if s.name == func_name:\n", " return s.ttot\n", "\n", "def aergia_extract_values_by_func(samples, func_name):\n", " '''Returns the total number of samples for function name, given an\n", " Aergia SAMPLES object.'''\n", " return sum(\n", " value for key, value in samples.items()\n", " if key.func == func_name\n", " )" ] }, { "cell_type": "markdown", "id": "25d725bd", "metadata": {}, "source": [ "Next, a small function which actually runs the iterations and does the plotting:" ] }, { "cell_type": "code", "execution_count": 11, "id": "0dd177cf", "metadata": {}, "outputs": [], "source": [ "import time" ] }, { "cell_type": "code", "execution_count": 12, "id": "09420196", "metadata": {}, "outputs": [], "source": [ "def compare_coro(call, func_to_profile, iterations):\n", " '''Calls CALL with each element of ITERATIONS under both\n", " yappi and Aergia. Maintains the profiling information for\n", " FUNC_TO_PROFILE and returns the results.'''\n", " y_res = []\n", " a_res = []\n", " t_res = []\n", " for n, i in enumerate(iterations):\n", " res = run_with_aergia(call(i), False)\n", " a_res.append(aergia_extract_values_by_func(res, func_to_profile))\n", "\n", " res = run_with_yappi(call(i), False)\n", " y_res.append(yappi_extract_values_by_func(res, func_to_profile))\n", " \n", " start = time.perf_counter()\n", " run_coro(call(i))\n", " t_res.append(time.perf_counter() - start)\n", "\n", " if ((n + 1) % 5 == 0):\n", " print(f'Completed iteration {n + 1}.')\n", " \n", " return y_res, a_res, t_res" ] }, { "cell_type": "code", "execution_count": 15, "id": "7141ba1c", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'time' is not defined", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[15]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m iterations = \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mrange\u001b[39m(\u001b[32m100\u001b[39m, \u001b[32m1000\u001b[39m, \u001b[32m200\u001b[39m))\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m yres, ares, tres = \u001b[43mcompare_coro\u001b[49m\u001b[43m(\u001b[49m\u001b[43malarm\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43msnooze\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43miterations\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[14]\u001b[39m\u001b[32m, line 15\u001b[39m, in \u001b[36mcompare_coro\u001b[39m\u001b[34m(call, func_to_profile, iterations)\u001b[39m\n\u001b[32m 12\u001b[39m res = run_with_yappi(call(i), \u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[32m 13\u001b[39m y_res.append(yappi_extract_values_by_func(res, func_to_profile))\n\u001b[32m---> \u001b[39m\u001b[32m15\u001b[39m start = \u001b[43mtime\u001b[49m.perf_counter()\n\u001b[32m 16\u001b[39m run_coro(call(i))\n\u001b[32m 17\u001b[39m t_res.append(time.perf_counter() - start)\n", "\u001b[31mNameError\u001b[39m: name 'time' is not defined" ] } ], "source": [ "iterations = list(range(100, 1000, 200))\n", "\n", "yres, ares, tres = compare_coro(alarm, 'snooze', iterations)" ] }, { "cell_type": "markdown", "id": "0c962138", "metadata": {}, "source": [ "To help visualize, I'll use plotly:" ] }, { "cell_type": "code", "execution_count": 13, "id": "cb5936dc", "metadata": { "scrolled": true }, "outputs": [], "source": [ "import plotly.graph_objects as go" ] }, { "cell_type": "code", "execution_count": 14, "id": "bca40c72", "metadata": {}, "outputs": [], "source": [ "def plot_comp(func_name, iterations, aergia, yappi, ideal=None, color1='blue', color2='red', color3='green'):\n", " fig = go.Figure()\n", "\n", " fig.add_trace(go.Scatter(x=iterations, y=aergia, mode='markers', name='aergia', marker=dict(color=color1)))\n", " fig.add_trace(go.Scatter(x=iterations, y=yappi, mode='markers', name='yappi', marker=dict(color=color2)))\n", " if ideal:\n", " fig.add_trace(go.Scatter(x=iterations, y=ideal, mode='lines', name='ideal', line=dict(color=color3)))\n", "\n", "\n", " fig.update_layout(\n", " title=f'Reported Seconds for Coroutine {func_name}',\n", " xaxis_title='number of suspends',\n", " yaxis_title='reported seconds',\n", " legend_title='Legend',\n", " )\n", "\n", "\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 16, "id": "ced7211f", "metadata": { "scrolled": false }, "outputs": [ { "ename": "NameError", "evalue": "name 'iterations' is not defined", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[16]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m plot_comp(\u001b[33m'\u001b[39m\u001b[33msnooze\u001b[39m\u001b[33m'\u001b[39m, \u001b[43miterations\u001b[49m, ares, yres, tres)\n", "\u001b[31mNameError\u001b[39m: name 'iterations' is not defined" ] } ], "source": [ "plot_comp('snooze', iterations, ares, yres, tres)" ] }, { "cell_type": "markdown", "id": "e4c56ca9", "metadata": {}, "source": [ "# asyncio.sleep (asynchronous)" ] }, { "cell_type": "markdown", "id": "fe542ae5", "metadata": {}, "source": [ "This code does the same as above, synchronously." ] }, { "cell_type": "code", "execution_count": 15, "id": "d5ae80e1", "metadata": {}, "outputs": [], "source": [ "async def alarm(times):\n", " tasks = [snooze() for _ in range(times)]\n", " await asyncio.gather(*tasks)" ] }, { "cell_type": "code", "execution_count": 27, "id": "45e9b10f", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Completed iteration 5.\n", "Completed iteration 10.\n", "Completed iteration 15.\n", "Completed iteration 20.\n", "Completed iteration 25.\n", "Completed iteration 30.\n", "Completed iteration 35.\n" ] } ], "source": [ "iterations = list(range(100, 4000, 100))\n", "yres, ares, tres = compare_coro(alarm, 'snooze', iterations)" ] }, { "cell_type": "code", "execution_count": 26, "id": "e33c1263", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "marker": { "color": "blue" }, "mode": "markers", "name": "aergia", "type": "scatter", "x": [ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900 ], "y": [ 2.005006419494748, 4.022378381341696, 6.063008587807417, 8.07199478149414, 15.027741901576519, 18.02756767719984, 21.205922681838274, 24.060998111963272, 27.207420067861676, 30.045913998037577, 33.184027718380094, 29.911083541810513, 39.21850915066898, 42.042862959206104, 45.27976457029581, 48.03103506565094, 108.42642900533974, 36.39472732320428, 57.152095437049866, 42.38697048276663, 63.30844033509493, 132.97371263429523, 81.73114294325933, 116.95187920471653, 73.20595596777275, 150.9596981923096, 155.436400459148, 209.72602259367704, 114.01065992517397, 147.56739552505314, 161.34091241657734, 324.7810024325736, 167.44374121632427, 97.48291622428223, 171.87959975609556, 133.67409747699276, 318.88608211046085, 140.35703712748364, 110.78012464055791 ] }, { "marker": { "color": "red" }, "mode": "markers", "name": "yappi", "type": "scatter", "x": [ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900 ], "y": [ 2.5950919999999997, 5.616319, 9.059268, 12.332991999999999, 15.301478, 17.120825, 24.201725, 26.93514, 30.613598999999997, 35.975335, 40.366104, 45.955129, 51.285728999999996, 58.522748, 66.292866, 71.760232, 92.410927, 98.248446, 116.13905299999999, 131.324099, 160.877873, 183.45910999999998, 186.28006499999998, 212.972286, 631.503736, 259.338771, 318.884748, 314.797732, 364.56521399999997, 370.41099099999997, 420.08628, 432.739113, 1028.895783, 538.50839, 914.678376, 612.6363719999999, 617.604426, 719.446907, 720.276751 ] }, { "line": { "color": "green" }, "mode": "lines", "name": "ideal", "type": "scatter", "x": [ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900 ], "y": [ 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 50, 52.5, 55, 57.5, 60, 62.5, 65, 67.5, 70, 72.5, 75, 77.5, 80, 82.5, 85, 87.5, 90, 92.5, 95, 97.5 ] } ], "layout": { "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine snooze" }, "xaxis": { "title": { "text": "tasks run simultaniously" } }, "yaxis": { "title": { "text": "reported seconds" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ideal = [x * 0.025 for x in iterations]\n", "plot_comp('snooze', iterations, ares, yres, ideal)" ] }, { "cell_type": "markdown", "id": "cf618932", "metadata": {}, "source": [ "# [aiofile](https://pypi.org/project/aiofiles/)" ] }, { "cell_type": "code", "execution_count": 21, "id": "aed763cb", "metadata": {}, "outputs": [], "source": [ "import aiofiles\n", "import os" ] }, { "cell_type": "markdown", "id": "65c94910", "metadata": {}, "source": [ "aiofiles is a rewrite of the file library, capable of accessing the user's file system asynchronously. It does this by using threads---given this will tax the GIL, we should see both aergia and yappi reflect a slowdown." ] }, { "cell_type": "code", "execution_count": 22, "id": "8061a64f", "metadata": {}, "outputs": [], "source": [ "async def read_file(filename):\n", " async with aiofiles.open(filename, mode='r') as f:\n", " content = await f.read()\n", " return content\n", "\n", "async def read_lots(iterations):\n", " filename = os.path.join(os.getcwd(), 'test.txt')\n", " tasks = [read_file(filename) for _ in range(iterations)]\n", " await asyncio.gather(*tasks)" ] }, { "cell_type": "code", "execution_count": 23, "id": "4af6cc84", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Completed iteration 5.\n", "Completed iteration 10.\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "line": { "color": "blue" }, "mode": "lines", "name": "aergia", "type": "scatter", "x": [ 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700 ], "y": [ 0.5, 6.44, 6.1000000000000005, 10.49, 18.43, 24.77, 31.84, 43.84, 61.04, 89.31, 113.47, 126.51, 157.72, 193.65 ] }, { "line": { "color": "red" }, "mode": "lines", "name": "yappi", "type": "scatter", "x": [ 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700 ], "y": [ 1.4477119999999999, 7.193809, 12.860985999999999, 18.999593, 33.065871, 51.779011999999994, 64.270523, 81.73268499999999, 118.55004699999999, 138.14200599999998, 163.586245, 194.296045, 269.978654, 267.408361 ] } ], "layout": { "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine read_file" }, "xaxis": { "title": { "text": "tasks run simultaniously" } }, "yaxis": { "title": { "text": "reported seconds" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iterations = list(range(50, 750, 50))\n", "func_name = 'read_file'\n", "\n", "yres, ares, tres = compare_coro(read_lots, func_name, iterations)\n", "plot_comp(func_name, iterations, ares, yres)" ] }, { "cell_type": "markdown", "id": "915b9cd6", "metadata": {}, "source": [ "## Blocking the Event Loop" ] }, { "cell_type": "markdown", "id": "f94fb172", "metadata": {}, "source": [ "This test should really demonstrate extra overhead" ] }, { "cell_type": "code", "execution_count": 34, "id": "b29247f3", "metadata": {}, "outputs": [], "source": [ "import time\n", "from aiohttp import web\n", "import aiohttp" ] }, { "cell_type": "code", "execution_count": 32, "id": "3f73797c", "metadata": {}, "outputs": [], "source": [ "START_TIME = time.perf_counter()\n", "READ_URL = \"http://localhost:8080/{size}/read\"\n", "TALK_URL = \"http://localhost:8080/talk\"\n", "FILE_SIZE_TO_TIME = {\n", " \"biggest\": 0.500,\n", " \"big\": 0.443, # the scalene paper\n", " \"medium\": 0.012,\n", " \"small\": 0.004,\n", "}\n", "\n", "async def read_file(request):\n", " '''Mock implementation for reading a file. This is always a blocking\n", " operation because it requires the OS to retrieve data from disk.'''\n", " size = request.match_info.get(\"size\", \"small\") # default to small\n", " read_time = FILE_SIZE_TO_TIME[size]\n", " if BLOCKING_CALL:\n", " time.sleep(read_time)\n", " else:\n", " loop = asyncio.get_running_loop()\n", " await loop.run_in_executor(None, time.sleep, read_time)\n", " return web.Response(status=200, text=f\"Read for {read_time}\")\n", "\n", "async def talk_to_server(request):\n", " '''Mock implementation for requesting information from another server.\n", " For simplicity, requests always take 40 milliseconds.'''\n", " await asyncio.sleep(0.04)\n", " return web.Response(status=200, text=f\"Talk for {sleep_time}\")" ] }, { "cell_type": "code", "execution_count": 36, "id": "3fdd3873", "metadata": {}, "outputs": [], "source": [ "app = web.Application()\n", "app.router.add_post(\"/{size}/read\", read_file)\n", "app.router.add_post(\"/talk\", talk_to_server)\n", "runner = web.AppRunner(app)" ] }, { "cell_type": "code", "execution_count": 37, "id": "429c5629", "metadata": {}, "outputs": [], "source": [ "async def start_server():\n", " await runner.setup()\n", " site = web.TCPSite(runner, \"localhost\", 8080)\n", " await site.start()\n", "\n", "\n", "async def stop_server():\n", " await runner.cleanup()" ] }, { "cell_type": "markdown", "id": "743f99ee", "metadata": {}, "source": [ "Now we need a mock 'client' which will invoke these endpoints, as well as a main function to make queue multiple requests at once." ] }, { "cell_type": "code", "execution_count": 38, "id": "0cb5ffb8", "metadata": {}, "outputs": [], "source": [ "async def request(client: aiohttp.ClientSession, url: str):\n", " async with client.request(\"POST\", url) as response:\n", "\n", " if response.status == 200:\n", " print(f\"Finished {url} at {time.perf_counter() - START_TIME}\")\n", " else:\n", " print(f\"Request failed with status: {response.status}\")" ] }, { "cell_type": "code", "execution_count": 39, "id": "c7460541", "metadata": {}, "outputs": [], "source": [ "async def main(keys) -> list:\n", " await start_server()\n", " # wait for server to start\n", " await asyncio.sleep(0.5)\n", "\n", " async with aiohttp.ClientSession() as session:\n", " tasks = []\n", " for key in keys:\n", " if key == \"talk\":\n", " task = asyncio.create_task(\n", " request(session, TALK_URL))\n", " else:\n", " task = asyncio.create_task(\n", " request(session, READ_URL.format(size=key)))\n", " tasks.append(task)\n", "\n", " return await asyncio.gather(*tasks)" ] }, { "cell_type": "markdown", "id": "82770b60", "metadata": {}, "source": [ "## Recursion" ] }, { "cell_type": "code", "execution_count": 73, "id": "352dc093", "metadata": {}, "outputs": [], "source": [ "delay = 0.1\n", "async def recurse(n):\n", " if n <= 0:\n", " return\n", " await asyncio.sleep(delay)\n", " await recurse(n - 1)\n", " await recurse(n - 2)" ] }, { "cell_type": "code", "execution_count": 82, "id": "e99b7e87", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FILE FUNC PERC (ACTUAL -> SEC)\n", "ernel_26033/2712533979.py:5 recurse 33.333% (542.000 -> 5.420000)\n", "kernel_26033/510785827.py:4 run_coro 33.333% (542.000 -> 5.420000)\n", "kernel_26033/510785827.py:2 33.333% (542.000 -> 5.420000)\n", "FILE FUNC SEC \n", "kernel_26033/510785827.py:1 run_coro 5.4423 \n", "kernel_26033/510785827.py:2 5.4407 \n", "ernel_26033/2712533979.py:2 recurse 5.4378 \n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "run_with_aergia(recurse(8), True)\n", "run_with_yappi(recurse(8), True)" ] }, { "cell_type": "code", "execution_count": 80, "id": "bbbcfd32", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Completed iteration 5.\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "line": { "color": "blue" }, "mode": "lines", "name": "aergia", "type": "scatter", "x": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "y": [ 0.1, 0.2, 0.4, 0.7000000000000001, 1.2, 2.0100000000000002, 3.31, 5.42, 8.84 ] }, { "line": { "color": "red" }, "mode": "lines", "name": "yappi", "type": "scatter", "x": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "y": [ 0.10106899999999999, 0.201534, 0.40232999999999997, 0.705199, 1.2086569999999999, 2.014402, 3.3209109999999997, 5.439819, 8.859999 ] } ], "layout": { "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine recurse" }, "xaxis": { "title": { "text": "tasks run simultaniously" } }, "yaxis": { "title": { "text": "reported seconds" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iterations = list(range(1, 10, 1))\n", "func_name = 'recurse'\n", "\n", "yres, ares, tres = compare_coro(recurse, func_name, iterations)\n", "plot_comp(func_name, iterations, ares, yres)" ] }, { "cell_type": "markdown", "id": "b5e49dad", "metadata": {}, "source": [ "## Percentages" ] }, { "cell_type": "code", "execution_count": 55, "id": "927af260", "metadata": {}, "outputs": [], "source": [ "tot = 3.0\n", "\n", "async def sleeper(decimal):\n", " await asyncio.sleep(tot * decimal)\n", "\n", "async def split(decimal):\n", " await asyncio.sleep(tot * decimal)\n", " await sleeper(1.0 - decimal)" ] }, { "cell_type": "code", "execution_count": 37, "id": "5f0a2143", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 57, "id": "6ea889f3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Completed iteration 5.\n", "Completed iteration 10.\n", "Completed iteration 15.\n", "Completed iteration 20.\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "line": { "color": "blue" }, "mode": "lines", "name": "aergia", "type": "scatter", "x": [ 0, 0.05, 0.1, 0.15000000000000002, 0.2, 0.25, 0.30000000000000004, 0.35000000000000003, 0.4, 0.45, 0.5, 0.55, 0.6000000000000001, 0.65, 0.7000000000000001, 0.75, 0.8, 0.8500000000000001, 0.9, 0.9500000000000001, 1 ], "y": [ 0, 0.15009622182697058, 0.30011437414214015, 0.45024808775633574, 0.6002707849256694, 0.7502208026126027, 0.9001351818442345, 1.0502264993265271, 1.2002556379884481, 1.3501644786447287, 1.500193199608475, 1.6501498259603977, 1.8002629317343235, 1.9501247801817954, 2.1001115990802646, 2.2501964289695024, 2.4001767858862877, 2.550205725710839, 2.7002862547524273, 2.8501306800171733, 3.0004976578056812 ] }, { "line": { "color": "red" }, "mode": "lines", "name": "yappi", "type": "scatter", "x": [ 0, 0.05, 0.1, 0.15000000000000002, 0.2, 0.25, 0.30000000000000004, 0.35000000000000003, 0.4, 0.45, 0.5, 0.55, 0.6000000000000001, 0.65, 0.7000000000000001, 0.75, 0.8, 0.8500000000000001, 0.9, 0.9500000000000001, 1 ], "y": [ 3.2999999999999996e-05, 0.150732, 0.30107999999999996, 0.451211, 0.601286, 0.751298, 0.90208, 1.0515349999999999, 1.201754, 1.351721, 1.502395, 1.65337, 1.802042, 1.9524549999999998, 2.101533, 2.252353, 2.4030609999999997, 2.552413, 2.7036089999999997, 2.8514489999999997, 3.002735 ] }, { "line": { "color": "green" }, "mode": "lines", "name": "ideal", "type": "scatter", "x": [ 0, 0.05, 0.1, 0.15000000000000002, 0.2, 0.25, 0.30000000000000004, 0.35000000000000003, 0.4, 0.45, 0.5, 0.55, 0.6000000000000001, 0.65, 0.7000000000000001, 0.75, 0.8, 0.8500000000000001, 0.9, 0.9500000000000001, 1 ], "y": [ 0.0007268860936164856, 0.15181733295321465, 0.30111302714794874, 0.4524425766430795, 0.6026221080683172, 0.7527396096847951, 0.9020893340930343, 1.052568478975445, 1.2025728281587362, 1.3535371590405703, 1.503610004670918, 1.6543716248124838, 1.8023136099800467, 1.9535730369389057, 2.1034863088279963, 2.2541096741333604, 2.4044889067299664, 2.555527030956, 2.7036496619693935, 2.8524399916641414, 3.0050483238883317 ] } ], "layout": { "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine sleeper" }, "xaxis": { "title": { "text": "tasks run simultaniously" } }, "yaxis": { "title": { "text": "reported seconds" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iterations = list(np.arange(0, 1.05, 0.05))\n", "func_name = 'sleeper'\n", "\n", "yres, ares, tres = compare_coro(sleeper, func_name, iterations)\n", "plot_comp(func_name, iterations, ares, yres, tres)" ] }, { "cell_type": "markdown", "id": "f8984f04", "metadata": {}, "source": [ "## Many Suspends" ] }, { "cell_type": "code", "execution_count": 57, "id": "eec6611f", "metadata": {}, "outputs": [], "source": [ "incre = 0.01\n", "async def loop(total_time):\n", " elapsed = 0\n", " while (elapsed < total_time):\n", " await asyncio.sleep(incre)\n", " elapsed += incre" ] }, { "cell_type": "code", "execution_count": 56, "id": "a7e659ec", "metadata": {}, "outputs": [], "source": [ "incre = 0.01\n", "async def loop_sync(total_time):\n", " elapsed = 0\n", " while (elapsed < total_time):\n", " time.sleep(incre)\n", " elapsed += incre" ] }, { "cell_type": "code", "execution_count": 19, "id": "118d13ea", "metadata": {}, "outputs": [], "source": [ "total_time = 0.5\n", "async def loop(iterations):\n", " elapsed = 0\n", " sleep_time = total_time / iterations\n", " while (elapsed < total_time):\n", " await asyncio.sleep(sleep_time)\n", " elapsed += sleep_time" ] }, { "cell_type": "code", "execution_count": 27, "id": "a34751ac", "metadata": {}, "outputs": [], "source": [ "total_time = 3.0\n", "async def loop(iterations):\n", " t0 = time.perf_counter()\n", " elapsed = 0\n", " sleep_time = total_time / iterations\n", " while (elapsed < total_time):\n", " await asyncio.sleep(sleep_time)\n", " elapsed = time.perf_counter() - t0" ] }, { "cell_type": "code", "execution_count": 21, "id": "f71f632f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FILE FUNC SEC \n", "kernel_11465/510785827.py:1 run_coro 1.3483 \n", "kernel_11465/510785827.py:2 1.3467 \n", "kernel_11465/369181571.py:2 loop 1.3281 \n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "run_with_yappi(loop(300), True)" ] }, { "cell_type": "code", "execution_count": 64, "id": "38fab937", "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots" ] }, { "cell_type": "code", "execution_count": 69, "id": "b4b6c880", "metadata": {}, "outputs": [], "source": [ "def plot_comp_suspends(func_name,\n", " iterations,\n", " aergia_async,\n", " yappi_async,\n", " aergia_sleep,\n", " yappi_sleep,\n", " ideal_async=None,\n", " ideal_sleep=None,\n", " color1='blue',\n", " color2='red',\n", " color3='green',\n", " color4='purple',\n", " color5='yellow',\n", " color6='orange'):\n", " fig = go.Figure()\n", "\n", " fig.add_trace(go.Scatter(x=iterations, y=aergia_async, mode='markers', name='aergia (async)', marker=dict(color=color1)))\n", " fig.add_trace(go.Scatter(x=iterations, y=yappi_async, mode='markers', name='yappi (async)', marker=dict(color=color2)))\n", " fig.add_trace(go.Scatter(x=iterations, y=aergia_sleep, mode='markers', name='aergia (sync)', marker=dict(color=color4)))\n", " fig.add_trace(go.Scatter(x=iterations, y=yappi_sleep, mode='markers', name='yappi (sync)', marker=dict(color=color5)))\n", " if ideal_async:\n", " fig.add_trace(go.Scatter(x=iterations, y=ideal_async, mode='lines', name='ideal (async)', line=dict(color=color3)))\n", " if ideal_sleep:\n", " fig.add_trace(go.Scatter(x=iterations, y=ideal_sleep, mode='lines', name='ideal (sync)', line=dict(color=color6)))\n", "\n", "\n", " fig.update_layout(\n", " title=f'Reported Seconds for Coroutine {func_name}',\n", " xaxis_title='number of suspends',\n", " yaxis_title='reported seconds',\n", " legend_title='Legend',\n", " )\n", " \n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 84, "id": "b677bd41", "metadata": {}, "outputs": [], "source": [ "def plot_comp_suspends(func_name,\n", " iterations,\n", " aergia_async,\n", " yappi_async,\n", " aergia_sleep,\n", " yappi_sleep,\n", " ideal_async=None,\n", " ideal_sleep=None,\n", " color1='blue',\n", " color2='red',\n", " color3='green'):\n", "\n", " fig = make_subplots(rows=1, cols=2, subplot_titles=('Asynchronous', 'Synchronous'))\n", "\n", " # async\n", " fig.add_trace(go.Scatter(x=iterations, y=aergia_async, mode='markers', name='aergia', marker=dict(color=color1)), row=1, col=1)\n", " fig.add_trace(go.Scatter(x=iterations, y=yappi_async, mode='markers', name='yappi', marker=dict(color=color2)), row=1, col=1)\n", " if ideal_async:\n", " fig.add_trace(go.Scatter(x=iterations, y=ideal_async, mode='lines', name='ideal', line=dict(color=color3)), row=1, col=1)\n", " \n", " # sync\n", " fig.add_trace(go.Scatter(x=iterations, y=aergia_sleep, mode='markers', marker=dict(color=color1)), row=1, col=2)\n", " fig.add_trace(go.Scatter(x=iterations, y=yappi_sleep, mode='markers', marker=dict(color=color2)), row=1, col=2)\n", " if ideal_sleep:\n", " fig.add_trace(go.Scatter(x=iterations, y=ideal_sleep, mode='lines', line=dict(color=color3)), row=1, col=2)\n", "\n", "\n", " fig.update_layout(\n", " title=f'Reported Seconds for Coroutine {func_name}',\n", " xaxis_title='supplied seconds',\n", " yaxis_title='reported seconds',\n", " legend_title='Legend',\n", " )\n", " \n", " fig.update_xaxes(title_text='supplied seconds', row=1, col=2)\n", "\n", " fig.for_each_trace(lambda trace: trace.update(showlegend=False) if trace.name not in ['aergia', 'yappi', 'ideal'] else trace.update(showlegend=True))\n", "\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 71, "id": "5fa03e58", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Completed iteration 5.\n", "Completed iteration 10.\n", "Completed iteration 15.\n", "Completed iteration 20.\n", "Completed iteration 5.\n", "Completed iteration 10.\n", "Completed iteration 15.\n", "Completed iteration 20.\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "marker": { "color": "blue" }, "mode": "markers", "name": "aergia (async)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.0300953341647983, 1.0802009324543178, 1.1401102892123163, 1.2001721197739244, 1.2402368150651455, 1.300108595751226, 1.3402596428059042, 1.4102244419045746, 1.4502821927890182, 1.5102193402126431, 1.550266901962459, 1.6102515012025833, 1.6602449710480869, 1.7102482449263334, 1.7601053649559617, 1.8102183281444013, 1.870239730924368, 1.920077980030328, 1.9701147247105837, 2.020098625216633, 2.070262962952256 ] }, { "marker": { "color": "red" }, "mode": "markers", "name": "yappi (async)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.0531409999999999, 1.105372, 1.169269, 1.222488, 1.272761, 1.321475, 1.369121, 1.437926, 1.488507, 1.516986, 1.579901, 1.63968, 1.690458, 1.74538, 1.7913219999999999, 1.852539, 1.900307, 1.954483, 2.0048749999999997, 2.077261, 2.115004 ] }, { "marker": { "color": "purple" }, "mode": "markers", "name": "aergia (sync)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.020435520913452, 1.0601372215896845, 1.120198197197169, 1.1701389467343688, 1.2204098380170763, 1.2702048257924616, 1.3202419900335371, 1.3703030860051513, 1.4302367977797985, 1.4803100978024304, 1.5301465331576765, 1.5803418941795826, 1.6401383159682155, 1.680330959148705, 1.740354185923934, 1.7801085580140352, 1.8402847493998706, 1.8802420520223677, 1.9401059318333864, 1.9902589921839535, 2.0303331739269197 ] }, { "marker": { "color": "yellow" }, "mode": "markers", "name": "yappi (sync)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.027583, 1.076679, 1.128027, 1.1794639999999998, 1.2273049999999999, 1.278257, 1.33124, 1.381762, 1.432516, 1.4863279999999999, 1.5378459999999998, 1.58412, 1.6415819999999999, 1.694651, 1.74063, 1.7917779999999999, 1.841894, 1.8937629999999999, 1.944521, 1.991728, 2.0460819999999997 ] }, { "line": { "color": "green" }, "mode": "lines", "name": "ideal (async)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.0381560889072716, 1.0935737527906895, 1.1415139031596482, 1.1995012792758644, 1.2570461612194777, 1.3015670850872993, 1.3514276333153248, 1.4129177499562502, 1.461818407755345, 1.5046086576767266, 1.568426975980401, 1.613852680195123, 1.6711010057479143, 1.7146760928444564, 1.7666827039793134, 1.8171685934066772, 1.8699824321083724, 1.9171160878613591, 1.9652346018701792, 2.026691841892898, 2.085880281869322 ] }, { "line": { "color": "orange" }, "mode": "lines", "name": "ideal (sync)", "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "y": [ 1.0254312087781727, 1.0748692457564175, 1.1298753069713712, 1.1770338122732937, 1.2249595350585878, 1.2809668709523976, 1.332599949091673, 1.3825336652807891, 1.4344221390783787, 1.4828009270131588, 1.5348775018937886, 1.581768977921456, 1.6351896738633513, 1.689969011116773, 1.7393375630490482, 1.7919335379265249, 1.8398224981501698, 1.888107960112393, 1.9374144719913602, 1.9958957210183144, 2.040139697957784 ] } ], "layout": { "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine loop" }, "xaxis": { "title": { "text": "number of suspends" } }, "yaxis": { "title": { "text": "reported seconds" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iterations = list(np.arange(1, 2.05, 0.05))\n", "func_name = 'loop'\n", "\n", "yres, ares, tres = compare_coro(loop, func_name, iterations)\n", "yres_s, ares_s, tres_s = compare_coro(loop_sync, 'loop_sync', iterations)\n", "plot_comp_suspends(func_name, iterations, ares, yres, ares_s, yres_s, tres, tres_s)" ] }, { "cell_type": "code", "execution_count": 85, "id": "9414e710", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "marker": { "color": "blue" }, "mode": "markers", "name": "aergia", "showlegend": true, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x", "y": [ 1.0300953341647983, 1.0802009324543178, 1.1401102892123163, 1.2001721197739244, 1.2402368150651455, 1.300108595751226, 1.3402596428059042, 1.4102244419045746, 1.4502821927890182, 1.5102193402126431, 1.550266901962459, 1.6102515012025833, 1.6602449710480869, 1.7102482449263334, 1.7601053649559617, 1.8102183281444013, 1.870239730924368, 1.920077980030328, 1.9701147247105837, 2.020098625216633, 2.070262962952256 ], "yaxis": "y" }, { "marker": { "color": "red" }, "mode": "markers", "name": "yappi", "showlegend": true, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x", "y": [ 1.0531409999999999, 1.105372, 1.169269, 1.222488, 1.272761, 1.321475, 1.369121, 1.437926, 1.488507, 1.516986, 1.579901, 1.63968, 1.690458, 1.74538, 1.7913219999999999, 1.852539, 1.900307, 1.954483, 2.0048749999999997, 2.077261, 2.115004 ], "yaxis": "y" }, { "line": { "color": "green" }, "mode": "lines", "name": "ideal", "showlegend": true, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x", "y": [ 1.0381560889072716, 1.0935737527906895, 1.1415139031596482, 1.1995012792758644, 1.2570461612194777, 1.3015670850872993, 1.3514276333153248, 1.4129177499562502, 1.461818407755345, 1.5046086576767266, 1.568426975980401, 1.613852680195123, 1.6711010057479143, 1.7146760928444564, 1.7666827039793134, 1.8171685934066772, 1.8699824321083724, 1.9171160878613591, 1.9652346018701792, 2.026691841892898, 2.085880281869322 ], "yaxis": "y" }, { "marker": { "color": "blue" }, "mode": "markers", "showlegend": false, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x2", "y": [ 1.020435520913452, 1.0601372215896845, 1.120198197197169, 1.1701389467343688, 1.2204098380170763, 1.2702048257924616, 1.3202419900335371, 1.3703030860051513, 1.4302367977797985, 1.4803100978024304, 1.5301465331576765, 1.5803418941795826, 1.6401383159682155, 1.680330959148705, 1.740354185923934, 1.7801085580140352, 1.8402847493998706, 1.8802420520223677, 1.9401059318333864, 1.9902589921839535, 2.0303331739269197 ], "yaxis": "y2" }, { "marker": { "color": "red" }, "mode": "markers", "showlegend": false, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x2", "y": [ 1.027583, 1.076679, 1.128027, 1.1794639999999998, 1.2273049999999999, 1.278257, 1.33124, 1.381762, 1.432516, 1.4863279999999999, 1.5378459999999998, 1.58412, 1.6415819999999999, 1.694651, 1.74063, 1.7917779999999999, 1.841894, 1.8937629999999999, 1.944521, 1.991728, 2.0460819999999997 ], "yaxis": "y2" }, { "line": { "color": "green" }, "mode": "lines", "showlegend": false, "type": "scatter", "x": [ 1, 1.05, 1.1, 1.1500000000000001, 1.2000000000000002, 1.2500000000000002, 1.3000000000000003, 1.3500000000000003, 1.4000000000000004, 1.4500000000000004, 1.5000000000000004, 1.5500000000000005, 1.6000000000000005, 1.6500000000000006, 1.7000000000000006, 1.7500000000000007, 1.8000000000000007, 1.8500000000000008, 1.9000000000000008, 1.9500000000000008, 2.000000000000001 ], "xaxis": "x2", "y": [ 1.0254312087781727, 1.0748692457564175, 1.1298753069713712, 1.1770338122732937, 1.2249595350585878, 1.2809668709523976, 1.332599949091673, 1.3825336652807891, 1.4344221390783787, 1.4828009270131588, 1.5348775018937886, 1.581768977921456, 1.6351896738633513, 1.689969011116773, 1.7393375630490482, 1.7919335379265249, 1.8398224981501698, 1.888107960112393, 1.9374144719913602, 1.9958957210183144, 2.040139697957784 ], "yaxis": "y2" } ], "layout": { "annotations": [ { "font": { "size": 16 }, "showarrow": false, "text": "Asynchronous", "x": 0.225, "xanchor": "center", "xref": "paper", "y": 1, "yanchor": "bottom", "yref": "paper" }, { "font": { "size": 16 }, "showarrow": false, "text": "Synchronous", "x": 0.775, "xanchor": "center", "xref": "paper", "y": 1, "yanchor": "bottom", "yref": "paper" } ], "legend": { "title": { "text": "Legend" } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reported Seconds for Coroutine loop" }, "xaxis": { "anchor": "y", "domain": [ 0, 0.45 ], "title": { "text": "supplied seconds" } }, "xaxis2": { "anchor": "y2", "domain": [ 0.55, 1 ], "title": { "text": "supplied seconds" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "reported seconds" } }, "yaxis2": { "anchor": "x2", "domain": [ 0, 1 ] } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot_comp_suspends(func_name, iterations, ares, yres, ares_s, yres_s, tres, tres_s)" ] }, { "cell_type": "code", "execution_count": null, "id": "f357c529", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "/gnu/store/c5qarpvwzcz1idryvvpiqd7738jn4rs1-python-3.11.11/bin/python3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }