@@ -3,10 +3,9 @@ Performance and the fast path
33===================================
44
55Wrapping a loop in a progress bar should not be the reason the loop gets
6- slower. progressbar2 has three layers aimed at that, each optional and each
7- falling back cleanly to the layer below it when unavailable. This page
8- covers what each one does, when it applies, and the measured cost of each,
9- so you know when reaching for one deliberately is worth it.
6+ slower. progressbar2 has three layers aimed at that: an always-on update
7+ gate, an automatic lean renderer, and an opt-in native iterator. This page
8+ covers what each one does, when it applies, and its measured cost.
109
1110Layer 1: the integer gate (always on)
1211==========================================
@@ -32,25 +31,26 @@ formatting.
3231
3332The fast class is chosen automatically when *all * of the following hold:
3433no explicit ``widgets= `` was given, ``fast `` was not passed as ``False ``,
35- no ``variables `` kwarg was given, ``unit `` is still the default ``'it' ``,
34+ ``variables `` is empty or not given, ``unit `` is still the default ``'it' ``,
3635``unit_scale `` is off, ``postfix `` is unset, and the
3736``PROGRESSBAR_DISABLE_FASTPATH `` environment variable is not set. In other
3837words: the common "just wrap my loop" case gets the lean renderer by
39- default; anything that needs the widget system (a custom widget list, tqdm's
38+ default. Anything that needs the widget system (a custom widget list, tqdm's
4039``unit ``/``postfix `` extras, dynamic ``Variable `` widgets) automatically
4140gets the full ``ProgressBar `` instead. You can also construct
4241:py:class: `~progressbar.fast.FastProgressBar ` directly if you want the fast
4342renderer without going through the shortcut -- see
4443:doc: `../reference/progressbar `.
4544
46- Note that this dispatch only happens inside ``progressbar.progressbar() ``.
45+ This dispatch only happens inside ``progressbar.progressbar() ``.
4746Constructing ``ProgressBar() `` yourself always gets the full class.
4847
4948Layer 3: the native iterator (opt-in via the ``fast `` extra)
5049==================================================================
5150
52- Separately, :py:meth: `ProgressBar.__iter__ <progressbar.bar.ProgressBar.__iter__> `
53- checks whether the optional ``speedups `` package
51+ Separately, :py:meth: `ProgressBar.__iter__
52+ <progressbar.bar.ProgressBar.__iter__> ` checks whether the optional
53+ ``speedups `` package
5454(``speedups.progressbar.FastBarIterator ``) is importable. If it is, and
5555``PROGRESSBAR_DISABLE_FASTPATH `` is not set, iterating over *any * bar --
5656fast or full -- dispatches to that native iterator instead of the
@@ -59,7 +59,7 @@ pure-Python generator. It counts items itself and calls back into the bar
5959gate crossings, so the per-iteration counting that Layer 1 already made
6060cheap in pure Python gets cheaper still.
6161
62- ``speedups `` is not installed by default; install it with the ``fast ``
62+ ``speedups `` is not installed by default. Install it with the ``fast ``
6363extra:
6464
6565.. code :: sh
@@ -71,7 +71,7 @@ above Layer 1: it stops ``progressbar.progressbar()`` from choosing
7171``FastProgressBar ``, stops ``__iter__ `` from choosing the native iterator,
7272*and * disables the integer gate itself in :py:meth: `ProgressBar.start()
7373<progressbar.bar.ProgressBar.start> ` -- with it set, every bar calls
74- ``update() `` on every single iteration, matching the pre-gate behaviour
74+ ``update() `` on every single iteration, matching the pre-gate behavior
7575exactly. That makes it a genuine "turn all of this off" switch, useful when
7676debugging a rendering issue you want to rule the gate out of, not just an
7777opt-out of the optional native accelerator.
@@ -81,8 +81,8 @@ Measured cost
8181
8282The following is reproduced from this repository's own benchmark suite
8383(``benchmarks/report.md ``, generated by ``python benchmarks/bench.py &&
84- python benchmarks/report.py ``; see that file for the full comparison against
85- other libraries). Figures are from one measurement environment (CPython
84+ python benchmarks/report.py ``, which also compares against other
85+ libraries). Figures are from one measurement environment (CPython
86863.13.12, macOS arm64, output to a real pty) and will vary by machine --
8787re-run the benchmark rather than treating these as guarantees:
8888
@@ -114,4 +114,4 @@ When to reach for which layer
114114 those features need the widget system that ``FastProgressBar `` skips.
115115* Install the ``fast `` extra when the iteration count itself is large
116116 enough (hundreds of millions of items) that even Layer 1's per-iteration
117- cost is worth shaving further; for most scripts it isn't necessary.
117+ cost is worth shaving further. For most scripts it isn't necessary.
0 commit comments