barflow 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- barflow-0.2.0/LICENSE +201 -0
- barflow-0.2.0/MANIFEST.in +21 -0
- barflow-0.2.0/PKG-INFO +433 -0
- barflow-0.2.0/README.md +400 -0
- barflow-0.2.0/benchmarks/bench.py +639 -0
- barflow-0.2.0/benchmarks/bench_first_frame.py +237 -0
- barflow-0.2.0/benchmarks/bench_memory.py +216 -0
- barflow-0.2.0/benchmarks/bench_metadata_churn.py +220 -0
- barflow-0.2.0/benchmarks/bench_multibar.py +208 -0
- barflow-0.2.0/benchmarks/bench_raw.md +56 -0
- barflow-0.2.0/benchmarks/bench_tail_latency.py +238 -0
- barflow-0.2.0/benchmarks/pgo_train.py +102 -0
- barflow-0.2.0/benchmarks/results.md +132 -0
- barflow-0.2.0/docs/DESIGN.md +388 -0
- barflow-0.2.0/docs/FEATURE_REQUESTS.md +138 -0
- barflow-0.2.0/docs/PUBLISHING.md +127 -0
- barflow-0.2.0/examples/async_stream.py +47 -0
- barflow-0.2.0/examples/parallel_presets.py +71 -0
- barflow-0.2.0/examples/showcase.py +124 -0
- barflow-0.2.0/examples/themes_showcase.py +84 -0
- barflow-0.2.0/pyproject.toml +64 -0
- barflow-0.2.0/setup.cfg +4 -0
- barflow-0.2.0/setup.py +175 -0
- barflow-0.2.0/src/barflow/__init__.py +78 -0
- barflow-0.2.0/src/barflow/_core.cpp +2168 -0
- barflow-0.2.0/src/barflow/_progress.py +42 -0
- barflow-0.2.0/src/barflow/aio.py +62 -0
- barflow-0.2.0/src/barflow/bar_styles.py +203 -0
- barflow-0.2.0/src/barflow/columns.py +148 -0
- barflow-0.2.0/src/barflow/hooks.py +118 -0
- barflow-0.2.0/src/barflow/spinners.py +85 -0
- barflow-0.2.0/src/barflow/style.py +162 -0
- barflow-0.2.0/src/barflow/themes.py +386 -0
- barflow-0.2.0/src/barflow.egg-info/PKG-INFO +433 -0
- barflow-0.2.0/src/barflow.egg-info/SOURCES.txt +35 -0
- barflow-0.2.0/src/barflow.egg-info/dependency_links.txt +1 -0
- barflow-0.2.0/src/barflow.egg-info/top_level.txt +1 -0
barflow-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include setup.py
|
|
5
|
+
include MANIFEST.in
|
|
6
|
+
|
|
7
|
+
recursive-include src/barflow *.py *.cpp *.h
|
|
8
|
+
recursive-include docs *.md
|
|
9
|
+
recursive-include benchmarks *.py *.md
|
|
10
|
+
recursive-include examples *.py
|
|
11
|
+
|
|
12
|
+
global-exclude __pycache__
|
|
13
|
+
global-exclude *.py[cod]
|
|
14
|
+
global-exclude *.pyd
|
|
15
|
+
global-exclude *.so
|
|
16
|
+
global-exclude *.dll
|
|
17
|
+
global-exclude .DS_Store
|
|
18
|
+
prune build
|
|
19
|
+
prune dist
|
|
20
|
+
prune .github
|
|
21
|
+
prune src/barflow/__pycache__
|
barflow-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: barflow
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Fast Python progress bars with a C++ core. Windows-first.
|
|
5
|
+
Author: NevermindNilas
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/NevermindNilas/barflow
|
|
8
|
+
Project-URL: Repository, https://github.com/NevermindNilas/barflow
|
|
9
|
+
Project-URL: Issues, https://github.com/NevermindNilas/barflow/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/NevermindNilas/barflow/releases
|
|
11
|
+
Project-URL: Documentation, https://github.com/NevermindNilas/barflow/blob/main/docs/DESIGN.md
|
|
12
|
+
Keywords: progress,progressbar,progress-bar,tqdm,rich,cli,terminal,spinner,cpp,c-extension,windows
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Programming Language :: C++
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: Terminals
|
|
28
|
+
Classifier: Topic :: Utilities
|
|
29
|
+
Requires-Python: >=3.13
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# BarFlow
|
|
35
|
+
|
|
36
|
+
**A fast Python progress bar library with a C++ core. Windows-first.**
|
|
37
|
+
Built to beat `tqdm`, `rich.progress`, and `alive-progress` on cold
|
|
38
|
+
import, per-iteration overhead, peak it/s, memory footprint, tail
|
|
39
|
+
latency, multi-bar throughput, and first-frame latency — simultaneously.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import barflow
|
|
43
|
+
|
|
44
|
+
# Fastest: `for _ in progress:` runs at 160+ M it/s — faster than
|
|
45
|
+
# a bare `for _ in range(n): pass` because Py_None is immortal.
|
|
46
|
+
with barflow.Progress(total=n, desc="Crunching") as p:
|
|
47
|
+
for _ in p:
|
|
48
|
+
do_work()
|
|
49
|
+
|
|
50
|
+
# When you also need the iterated values:
|
|
51
|
+
for x in barflow.track(range(1_000_000), desc="Working"):
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
# Event-driven / manual:
|
|
55
|
+
with barflow.Progress(total=n, desc="Streaming") as p:
|
|
56
|
+
for chunk in data:
|
|
57
|
+
process(chunk)
|
|
58
|
+
p.advance(len(chunk))
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Benchmarks
|
|
62
|
+
|
|
63
|
+
Numbers below are from `benchmarks/bench.py` on Windows 11 / Python
|
|
64
|
+
3.13 / N = 20,000,000 iterations (5 runs per data point, best wall
|
|
65
|
+
time for rate measurements, min CPU time for CPU measurements).
|
|
66
|
+
Baseline bare `for _ in range(n): pass` is **145.75 M it/s**
|
|
67
|
+
(6.9 ns/iter, 140.6 ms of CPU). Raw output lives in
|
|
68
|
+
`benchmarks/bench_raw.md`; methodology and platform notes are in
|
|
69
|
+
`benchmarks/results.md`.
|
|
70
|
+
|
|
71
|
+
### Headline
|
|
72
|
+
|
|
73
|
+
| Axis | BarFlow | tqdm | rich | alive-progress |
|
|
74
|
+
| ----------------------------------- | ------------: | ------: | ------: | -------------: |
|
|
75
|
+
| Cold import (ms) | **1.21** | 72.27 | 74.96 | 30.12 |
|
|
76
|
+
| Overhead, `for _ in p:` (ns/iter) | **0.0** | 7.4 | 471.9 | 384.9 |
|
|
77
|
+
| Overhead, `track(...)` (ns/iter) | **3.0** | 7.4 | 471.9 | 384.9 |
|
|
78
|
+
| Peak it/s, display off | **160.8 M** | 70.2 M | 2.1 M | 2.6 M |
|
|
79
|
+
| Peak it/s, display on | **101.8 M** | 19.6 M | 2.1 M | 2.1 M |
|
|
80
|
+
| Python heap peak (1 M iters) | **486 B** | 298 KB | 661 KB | 3.4 MB |
|
|
81
|
+
| Tail latency p99.9 (ns) | **100** | 200 | 2,200 | 2,200 |
|
|
82
|
+
| First-frame latency (µs) | **32** | 97 | 921 | n/a |
|
|
83
|
+
| Multi-bar, 4 tasks (M it/s) | **43.9 M** | 8.8 M | 2.2 M | n/a |
|
|
84
|
+
| Metadata churn (M it/s) | **29.6 M** | 6.6 M | 2.0 M | 1.9 M |
|
|
85
|
+
| Total CPU, display on (ms for 20 M) | **188** | 953 | 9,297 | 9,391 |
|
|
86
|
+
|
|
87
|
+
BarFlow wins on every axis — **25–62×** faster cold import, **zero
|
|
88
|
+
measurable overhead** on its iteration fast path (faster than a bare
|
|
89
|
+
`for _ in range(n)` because Py_None is immortal on 3.12+ and skips
|
|
90
|
+
the store-cycle refcount work that range's small-int yields incur),
|
|
91
|
+
**5.2×** display-on throughput vs tqdm, **~50×** vs rich / alive,
|
|
92
|
+
**600×+ less Python heap** peak, **2× tighter tail latency**, **3×
|
|
93
|
+
faster first-frame paint** than tqdm, and **~50×** less CPU than
|
|
94
|
+
rich / alive over 20 M iterations. The sub-1.0 CPU/wall ratio
|
|
95
|
+
reflects the decoupled render thread: it wakes on a 50 ms timeout,
|
|
96
|
+
formats into a preallocated buffer, and spends most of its life
|
|
97
|
+
parked on a condition variable, so the producer loop never pays for
|
|
98
|
+
rendering inline.
|
|
99
|
+
|
|
100
|
+
### Import startup (median, baseline-subtracted, 11 runs)
|
|
101
|
+
|
|
102
|
+
| Library | Cold import (ms) | vs BarFlow |
|
|
103
|
+
| ------- | ---------------: | ----------: |
|
|
104
|
+
| barflow | **1.21** | 1× |
|
|
105
|
+
| alive | 30.12 | 25× |
|
|
106
|
+
| tqdm | 72.27 | 60× |
|
|
107
|
+
| rich | 74.96 | 62× |
|
|
108
|
+
|
|
109
|
+
Measured by timing `python -c "from <lib> import ..."` in a
|
|
110
|
+
subprocess and subtracting a bare-interpreter baseline
|
|
111
|
+
(`python -c "pass"`), so the number is just the work the library
|
|
112
|
+
does at import time. BarFlow's module graph is deliberately lazy:
|
|
113
|
+
`themes`, `columns`, `style`, `spinners`, `hooks`, and `aio` are
|
|
114
|
+
all resolved on first attribute access via `__getattr__`, so the
|
|
115
|
+
cold import only pays for the C extension load and an `__init__.py`
|
|
116
|
+
that does nothing but expose `Progress`, `Tracker`, and `track`.
|
|
117
|
+
|
|
118
|
+
### No-display hot path — pure per-tick overhead
|
|
119
|
+
|
|
120
|
+
Display is disabled (`disable=True` where the library supports it)
|
|
121
|
+
so we measure the cost of advancing the counter, not rendering.
|
|
122
|
+
ns/iter is over the bare for-loop baseline.
|
|
123
|
+
|
|
124
|
+
| Variant | M it/s | ns/iter over baseline |
|
|
125
|
+
| ------------- | ---------: | --------------------: |
|
|
126
|
+
| barflow-iter | **160.76** | **0.0** |
|
|
127
|
+
| barflow-track | 101.13 | 3.0 |
|
|
128
|
+
| tqdm | 70.23 | 7.4 |
|
|
129
|
+
| barflow-tick | 65.39 | 8.4 |
|
|
130
|
+
| alive | 2.55 | 384.9 |
|
|
131
|
+
| rich | 2.09 | 471.9 |
|
|
132
|
+
|
|
133
|
+
- `barflow-iter` is `for _ in p:` — BarFlow's `Progress` type
|
|
134
|
+
implements the iteration protocol directly, so `FOR_ITER`
|
|
135
|
+
dispatches `tp_iternext` without the CPython vectorcall
|
|
136
|
+
trampoline. The iternext body is three x86 instructions
|
|
137
|
+
(`load`, `fetch_add`, `return Py_None`), and Py_None's
|
|
138
|
+
immortal refcount on 3.12+ means the loop's `STORE_FAST _`
|
|
139
|
+
is free. Net result: *below* the bare for-loop baseline,
|
|
140
|
+
because a `range`-driven loop still does refcount work on
|
|
141
|
+
its cached small-int yields.
|
|
142
|
+
- `barflow-track` is the `for x in barflow.track(iterable):`
|
|
143
|
+
wrapper, used when you also need the yielded values.
|
|
144
|
+
- `barflow-tick` is the manual `Progress.tick()` call from
|
|
145
|
+
Python, which pays the full CPython vectorcall dispatch
|
|
146
|
+
overhead per call. Use the iteration protocol above when you
|
|
147
|
+
don't have a source iterable.
|
|
148
|
+
|
|
149
|
+
### Display on — throughput with a live renderer
|
|
150
|
+
|
|
151
|
+
Comparator libraries write into an `io.StringIO` sink with
|
|
152
|
+
`force_terminal=True` so no real console I/O is measured. BarFlow
|
|
153
|
+
writes to its native Windows console path (no sink parameter),
|
|
154
|
+
which makes the comparison conservatively *worse* for BarFlow.
|
|
155
|
+
|
|
156
|
+
| Library | M it/s | vs BarFlow |
|
|
157
|
+
| -------------- | ---------: | ---------: |
|
|
158
|
+
| barflow | **101.76** | 1× |
|
|
159
|
+
| tqdm | 19.57 | 5.20× |
|
|
160
|
+
| rich | 2.11 | 48× |
|
|
161
|
+
| alive-progress | 2.09 | 49× |
|
|
162
|
+
|
|
163
|
+
BarFlow's render loop emits **delta frames**: each column's
|
|
164
|
+
previously-rendered bytes are cached, and on the next frame the
|
|
165
|
+
render thread emits `\x1b[<n>C` (cursor-right) over unchanged
|
|
166
|
+
spans instead of re-writing the bytes. On a real TTY this cuts
|
|
167
|
+
bytes-written per frame by roughly 60% for the default layout;
|
|
168
|
+
the sink-based benchmark above does not exercise the delta path,
|
|
169
|
+
so the number you see is the *lower bound* — real terminals get
|
|
170
|
+
more.
|
|
171
|
+
|
|
172
|
+
### Memory footprint
|
|
173
|
+
|
|
174
|
+
| Library | tracemalloc peak | RSS import | RSS run |
|
|
175
|
+
| -------------- | ---------------: | ---------: | -------: |
|
|
176
|
+
| barflow | **486 B** | 236 KB | 192 KB |
|
|
177
|
+
| tqdm | 298 KB | 6.83 MB | 992 KB |
|
|
178
|
+
| rich | 661 KB | 6.58 MB | 1.77 MB |
|
|
179
|
+
| alive-progress | 3.41 MB | 1.64 MB | 3.79 MB |
|
|
180
|
+
|
|
181
|
+
`tracemalloc peak` is the high-water mark of the Python heap over
|
|
182
|
+
a 1 M-iteration run (`bench_memory.py`). BarFlow's ~500 bytes is
|
|
183
|
+
effectively one `Progress` object's shell — the counter, output
|
|
184
|
+
buffer, render thread, and render scratch all live in C-owned
|
|
185
|
+
storage that `tracemalloc` cannot see. Competitors allocate
|
|
186
|
+
hundreds of KB to several MB of Python objects per run.
|
|
187
|
+
|
|
188
|
+
### Tail latency (per-iter distribution, display on)
|
|
189
|
+
|
|
190
|
+
| Library | p50 | p90 | p99 | p99.9 | max |
|
|
191
|
+
| -------------- | -------: | -----: | -------: | -------: | --------: |
|
|
192
|
+
| barflow | **100 ns** | 100 ns | 100 ns | **100 ns** | 7.80 µs |
|
|
193
|
+
| tqdm | 100 ns | 200 ns | 200 ns | 200 ns | 28.00 µs |
|
|
194
|
+
| rich | 500 ns | 600 ns | 800 ns | 2.20 µs | 153.20 µs |
|
|
195
|
+
| alive-progress | 500 ns | 600 ns | 700 ns | 2.20 µs | 138.00 µs |
|
|
196
|
+
|
|
197
|
+
Per-iter timestamps recorded with `perf_counter_ns()` across 100 K
|
|
198
|
+
iterations; `bench_tail_latency.py`. BarFlow is the only library
|
|
199
|
+
whose p99.9 does not diverge from its p50 — the render thread
|
|
200
|
+
never spills work onto the producer, so there is no jitter source
|
|
201
|
+
to create tail spikes.
|
|
202
|
+
|
|
203
|
+
### First-frame latency (`__enter__` to first byte)
|
|
204
|
+
|
|
205
|
+
| Library | median | min | p90 |
|
|
206
|
+
| ------- | -----: | ------: | ------: |
|
|
207
|
+
| barflow | **32 µs** | 28 µs | 41 µs |
|
|
208
|
+
| tqdm | 97 µs | 93 µs | 109 µs |
|
|
209
|
+
| rich | 921 µs | 845 µs | 1.05 ms |
|
|
210
|
+
|
|
211
|
+
BarFlow paints a synchronous first frame on `Progress.__enter__`
|
|
212
|
+
before the render thread takes over, eliminating the 50 ms
|
|
213
|
+
"blank bar" window that would otherwise be visible for
|
|
214
|
+
short-lived jobs. Measured by `bench_first_frame.py`.
|
|
215
|
+
|
|
216
|
+
### Multi-bar throughput (4 concurrent tasks)
|
|
217
|
+
|
|
218
|
+
| Library | wall time | aggregate |
|
|
219
|
+
| -------------- | --------: | ---------: |
|
|
220
|
+
| barflow | **22.8 ms** | **43.9 M it/s** |
|
|
221
|
+
| tqdm | 114.1 ms | 8.8 M it/s |
|
|
222
|
+
| rich | 465.8 ms | 2.2 M it/s |
|
|
223
|
+
| alive-progress | skipped (no clean multi-task API) | |
|
|
224
|
+
|
|
225
|
+
4 tasks × 250 K ticks each, driven round-robin from one thread
|
|
226
|
+
(`bench_multibar.py`). BarFlow stays lock-free — every task has
|
|
227
|
+
its own cache-line-padded counter, and the render thread walks
|
|
228
|
+
the task vector under a mutex that the hot path never touches.
|
|
229
|
+
|
|
230
|
+
### Metadata churn (description updated every 1 K iters)
|
|
231
|
+
|
|
232
|
+
| Library | wall time | it/s |
|
|
233
|
+
| -------------- | --------: | -------: |
|
|
234
|
+
| barflow | **33.8 ms** | **29.6 M** |
|
|
235
|
+
| tqdm | 152.4 ms | 6.6 M |
|
|
236
|
+
| rich | 514.1 ms | 2.0 M |
|
|
237
|
+
| alive-progress | 526.9 ms | 1.9 M |
|
|
238
|
+
|
|
239
|
+
1 M ticks, `set_description` called every 1000 ticks with a
|
|
240
|
+
pre-generated 40-char string (`bench_metadata_churn.py`).
|
|
241
|
+
BarFlow exposes `set_description(str)` and
|
|
242
|
+
`set_task_description(task_id, str)` that briefly acquire the
|
|
243
|
+
render mutex to swap the description; the lock-free tick hot
|
|
244
|
+
path is unaffected.
|
|
245
|
+
|
|
246
|
+
### CPU cost — render thread counted
|
|
247
|
+
|
|
248
|
+
`time.process_time()` sums user+system time across *every* thread
|
|
249
|
+
of the process (Windows `GetProcessTimes`, Linux
|
|
250
|
+
`CLOCK_PROCESS_CPUTIME_ID`, macOS `task_info`), so a background
|
|
251
|
+
render thread cannot hide from this measurement.
|
|
252
|
+
|
|
253
|
+
| Library | Mode | CPU ms (best of 5) | Extra ns/iter | CPU / wall |
|
|
254
|
+
| -------------- | ----------- | -----------------: | ------------: | ---------: |
|
|
255
|
+
| barflow | display-off | **187.5** | 2.3 | 0.96 |
|
|
256
|
+
| barflow | display-on | **187.5** | 2.3 | 0.96 |
|
|
257
|
+
| tqdm | display-off | 265.6 | 6.2 | 0.93 |
|
|
258
|
+
| tqdm | display-on | 953.1 | 40.6 | 0.95 |
|
|
259
|
+
| alive-progress | display-off | 7,671.9 | 376.6 | 0.98 |
|
|
260
|
+
| alive-progress | display-on | 9,390.6 | 462.5 | 0.98 |
|
|
261
|
+
| rich | display-off | 9,437.5 | 464.8 | 0.96 |
|
|
262
|
+
| rich | display-on | 9,296.9 | 457.8 | 0.98 |
|
|
263
|
+
|
|
264
|
+
Two things stand out:
|
|
265
|
+
|
|
266
|
+
1. **BarFlow's CPU cost is identical whether the display is on or
|
|
267
|
+
off.** Turning the bar on adds no measurable per-iter CPU
|
|
268
|
+
because the render thread wakes on a 50 ms condition-variable
|
|
269
|
+
timeout and spends the rest of its life parked. The producer
|
|
270
|
+
loop sees the same hot path in both modes.
|
|
271
|
+
2. **tqdm's CPU grows 3.6× when the display turns on** (266 →
|
|
272
|
+
953 ms), because rendering runs inline on the producer thread.
|
|
273
|
+
Rich and alive-progress sit near **~50×** BarFlow's CPU cost in
|
|
274
|
+
both modes — they pay hundreds of nanoseconds of dict/lock work
|
|
275
|
+
per `advance()` call before any rendering happens.
|
|
276
|
+
|
|
277
|
+
### Caveats / reproducibility
|
|
278
|
+
|
|
279
|
+
- Numbers are from a single Windows 11 box; absolute values will
|
|
280
|
+
differ on Linux / macOS but the ratios are stable in repeated
|
|
281
|
+
runs. Re-run `python benchmarks/bench.py --n 20000000 --runs 5`
|
|
282
|
+
to reproduce the main table, and `python benchmarks/bench_*.py`
|
|
283
|
+
for each extra axis (tail latency, memory, first-frame,
|
|
284
|
+
multi-bar, metadata churn).
|
|
285
|
+
- tqdm is run with `mininterval=0.05` (matching BarFlow's default)
|
|
286
|
+
rather than its out-of-box 0.10, so the comparison isolates
|
|
287
|
+
per-render work from render frequency instead of giving tqdm a
|
|
288
|
+
free 2× render-skip advantage.
|
|
289
|
+
- `time.process_time()` resolution is ~15 ms on Windows, so the
|
|
290
|
+
smallest CPU numbers (barflow: 187 ms) sit only ~12 ticks above
|
|
291
|
+
noise floor. Differences against tqdm (5×) and rich/alive (~50×)
|
|
292
|
+
are well outside that window.
|
|
293
|
+
- Display-on throughput is measured against an `io.StringIO` sink,
|
|
294
|
+
which skips Windows console latency. On a real TTY, BarFlow's
|
|
295
|
+
delta-render (cursor-advance over unchanged column spans) gives
|
|
296
|
+
it additional headroom that the StringIO harness cannot see.
|
|
297
|
+
|
|
298
|
+
## Install
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
pip install barflow
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Wheels are published for Windows (AMD64), Linux (x86_64, aarch64), and
|
|
305
|
+
macOS (x86_64, arm64) for CPython 3.13 and 3.14, including the
|
|
306
|
+
free-threaded `cp313t` / `cp314t` builds.
|
|
307
|
+
|
|
308
|
+
## Features
|
|
309
|
+
|
|
310
|
+
- **Zero-overhead iteration.** `for _ in progress:` runs at 160+ M
|
|
311
|
+
it/s — below the bare `for _ in range(n)` baseline, because
|
|
312
|
+
`FOR_ITER` dispatches directly to `tp_iternext` (no vectorcall
|
|
313
|
+
trampoline) and Py_None is immortal on 3.12+ (no refcount work
|
|
314
|
+
on `STORE_FAST`).
|
|
315
|
+
- **C++ hot path.** `tick`, `advance`, and `Tracker`'s iter-next
|
|
316
|
+
are single `std::atomic::fetch_add` calls with no locks and no
|
|
317
|
+
Python-level bookkeeping. Task counters are cache-line padded
|
|
318
|
+
so the render thread's reads never false-share with producer
|
|
319
|
+
writes.
|
|
320
|
+
- **Decoupled renderer.** A background thread wakes on a 50 ms
|
|
321
|
+
condition-variable timeout and formats into a preallocated buffer.
|
|
322
|
+
The producer never blocks.
|
|
323
|
+
- **Delta-render.** The render loop caches each column's previous
|
|
324
|
+
bytes and emits `\x1b[<n>C` cursor-advance over unchanged spans
|
|
325
|
+
instead of rewriting the frame. Roughly 60% fewer bytes written
|
|
326
|
+
per frame on the default layout.
|
|
327
|
+
- **Synchronous first frame.** `Progress.__enter__` paints one
|
|
328
|
+
frame inline before the render thread takes over, so short-lived
|
|
329
|
+
jobs don't see the 50 ms blank-bar window.
|
|
330
|
+
- **Windows-first.** Unconditional `ENABLE_VIRTUAL_TERMINAL_PROCESSING`,
|
|
331
|
+
UTF-16 transcoded `WriteConsoleW` chunked at 32 KB, legacy-console
|
|
332
|
+
fallback. No `colorama` dependency. A reusable `wscratch`
|
|
333
|
+
transcoding buffer means steady-state frames are zero-alloc.
|
|
334
|
+
- **Multi-task + columns.** 9 built-in column types
|
|
335
|
+
(description/bar/percent/count/rate/elapsed/eta/spinner/text),
|
|
336
|
+
rich-style column API, themes, ANSI cursor stacking for nested bars.
|
|
337
|
+
`Progress.set_description(str)` and `set_task_description(task_id, str)`
|
|
338
|
+
expose metadata churn without touching the lock-free hot path.
|
|
339
|
+
- **Spinner DSL.** Compositional factories
|
|
340
|
+
(`frame` / `scrolling` / `bouncing` / `alongside` / `sequential`)
|
|
341
|
+
compile to precomputed frame tables at `__enter__`.
|
|
342
|
+
- **`print()` interception.** `capture_output=True` reroutes
|
|
343
|
+
`sys.stdout` through `write_above()` so user prints appear above
|
|
344
|
+
live bars without tearing.
|
|
345
|
+
- **asyncio.** `barflow.aio.atrack(aiter)` wraps async iterables.
|
|
346
|
+
- **Tiny cold import.** `import barflow` is ~1.2 ms
|
|
347
|
+
(baseline-subtracted median) — 25–62× faster than the
|
|
348
|
+
alternatives. All non-core submodules (`themes`, `columns`,
|
|
349
|
+
`spinners`, `style`, `hooks`, `aio`) are lazy-loaded via
|
|
350
|
+
PEP 562 `__getattr__`.
|
|
351
|
+
- **Sub-kilobyte Python heap.** Peak `tracemalloc` usage across a
|
|
352
|
+
1 M-iteration run is ~500 bytes, vs 300 KB (tqdm), 660 KB (rich),
|
|
353
|
+
and 3.4 MB (alive-progress).
|
|
354
|
+
|
|
355
|
+
## Usage
|
|
356
|
+
|
|
357
|
+
```python
|
|
358
|
+
import barflow
|
|
359
|
+
from barflow.columns import (
|
|
360
|
+
SpinnerColumn, DescriptionColumn, BarColumn, PercentColumn,
|
|
361
|
+
CountColumn, RateColumn, EtaColumn,
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
# Simplest form — when you need the iterated values
|
|
365
|
+
for x in barflow.track(range(1000), desc="task"):
|
|
366
|
+
...
|
|
367
|
+
|
|
368
|
+
# Fastest form — when you just need a counter
|
|
369
|
+
with barflow.Progress(total=1000, desc="task") as p:
|
|
370
|
+
for _ in p:
|
|
371
|
+
do_work()
|
|
372
|
+
|
|
373
|
+
# Custom columns
|
|
374
|
+
with barflow.Progress(
|
|
375
|
+
SpinnerColumn(name="dots"), " ",
|
|
376
|
+
DescriptionColumn(), " ",
|
|
377
|
+
BarColumn(width=40, color="magenta"), " ",
|
|
378
|
+
PercentColumn(), " ",
|
|
379
|
+
CountColumn(), " | ", EtaColumn(),
|
|
380
|
+
total=1000, desc="build",
|
|
381
|
+
) as p:
|
|
382
|
+
for _ in range(1000):
|
|
383
|
+
p.tick()
|
|
384
|
+
|
|
385
|
+
# Named theme
|
|
386
|
+
with barflow.Progress(theme="classic", total=1000) as p:
|
|
387
|
+
...
|
|
388
|
+
|
|
389
|
+
# Multi-task
|
|
390
|
+
with barflow.Progress(theme="classic") as p:
|
|
391
|
+
dl = p.add_task(total=100, desc="download")
|
|
392
|
+
ex = p.add_task(total=100, desc="extract")
|
|
393
|
+
for i in range(100):
|
|
394
|
+
p.update(dl, 1)
|
|
395
|
+
p.update(ex, 1)
|
|
396
|
+
|
|
397
|
+
# Live prints during a bar
|
|
398
|
+
with barflow.Progress(total=100, capture_output=True) as p:
|
|
399
|
+
for i in range(100):
|
|
400
|
+
if i % 10 == 0:
|
|
401
|
+
print(f"checkpoint {i}") # appears above the bar
|
|
402
|
+
p.tick()
|
|
403
|
+
|
|
404
|
+
# asyncio
|
|
405
|
+
import asyncio, barflow.aio as aio
|
|
406
|
+
async def main():
|
|
407
|
+
async for x in aio.atrack(some_async_iter(), total=1000):
|
|
408
|
+
...
|
|
409
|
+
asyncio.run(main())
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Design
|
|
413
|
+
|
|
414
|
+
See `docs/DESIGN.md` for the full architecture: atomic hot path,
|
|
415
|
+
background render thread, column pipeline, Windows console handling,
|
|
416
|
+
and the benchmarks methodology.
|
|
417
|
+
|
|
418
|
+
## Build from source
|
|
419
|
+
|
|
420
|
+
Requires Visual Studio 2022+ (Windows) or GCC/Clang + Python headers
|
|
421
|
+
(POSIX) and Python ≥ 3.13.
|
|
422
|
+
|
|
423
|
+
```
|
|
424
|
+
# Windows
|
|
425
|
+
build.bat
|
|
426
|
+
|
|
427
|
+
# POSIX
|
|
428
|
+
python -m pip install -e .
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## License
|
|
432
|
+
|
|
433
|
+
MIT. See `LICENSE`.
|