Benchmarks

Benchmarks#

Added in version 0.9.0.

When used as a REPL (Read-Eval-Print Loop), this module starts slow since it builds on the standard library asyncio, which loads all its submodules on import, and the event loop is quite difficult to implement. This is understandable but suboptimal. On the contrary, we focus on simplifying boilerplate-heavy code and integrating and combining existing patterns seamlessly with a set of core utilities, so asyncutils is not at all heavy in terms of import time. In addition, you only pay for what you use; the parts of the code you don’t call are not executed until you request them to be, thanks to cleanly separated submodules with somewhat simplistic dependency graphs. This module is overall fast and light because of its design goals and philosophy.

The figures below are obtained by running each of the following sequentially with no warmup elevenfold in a fresh console session, then discarding the first run because it is treated as a warmup:

Baseline:

python -SEqX importtime -c "import asyncio"

Cumulative import time of asyncio: 122.60 ± 10.14 ms; max 138.83 ms, min 103.49 ms; n = 10

asyncutils:

python -SEqX importtime -c "import asyncutils"

Cumulative import time of asyncutils: 147.34 ± 7.53 ms; max 156.40 ms, min 131.94 ms; n = 10

Note

The figures below are relative to the time when asyncutils/__init__.py is executed, and may not reflect the actual time taken, because Python is not free to boot up itself, having to perform various initialization tasks.

python -SEqm asyncutils -dl

Time taken to start the console, which includes importing asyncio: 99.89 ± 6.19 ms; max 110.25 ms, min 91.97 ms, n = 10

python -SEqm asyncutils -dpl

Time taken to actually import asyncio along with all 32 submodules: 196.96 ± 18.30 ms; max 225.08 ms, min 172.51 ms, n = 10

Changed in version 0.9.6: Redid the benchmarks accurate to 0.01 ms.

Note

asyncio is still loaded early such that attribute accesses later on would not randomly take more than 100 ms, and you logically wouldn’t use this module without an async entry point, such that asyncio and its event loop are crucial and unavoidable.