Benchmarks
==========

.. version-added:: 0.9.0

When used as a REPL (Read-Eval-Print Loop), this module starts slow since it builds on the standard library :mod:`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 :mod:`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:

.. code-block:: bash

  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:

.. code-block:: bash

  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::
  :collapsible:

  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.

.. code-block:: bash

  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

.. code-block:: bash

  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

.. version-changed:: 0.9.6

  Redid the benchmarks accurate to 0.01 ms.

.. note::
  :collapsible:

  :mod:`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.
