2424 - [ Is there a ` dumps ` , ` write ` or ` encode ` function?] ( #is-there-a-dumps-write-or-encode-function )
2525 - [ How do TOML types map into Python types?] ( #how-do-toml-types-map-into-python-types )
2626- [ Performance] ( #performance )
27+ - [ Pure Python] ( #pure-python )
28+ - [ Mypyc generated wheel] ( #mypyc-generated-wheel )
2729
2830<!-- mdformat-toc end -->
2931
@@ -39,6 +41,11 @@ Tomli continues to provide a backport on PyPI for Python versions
3941where the standard library module is not available
4042and that have not yet reached their end-of-life.
4143
44+ Tomli uses [ mypyc] ( https://github.com/mypyc/mypyc )
45+ to generate binary wheels for most of the widely used platforms,
46+ so Python 3.11+ users may prefer it over ` tomllib ` for improved performance.
47+ Pure Python wheels are available on any platform and should perform the same as ` tomllib ` .
48+
4249## Installation<a name =" installation " ></a >
4350
4451``` bash
@@ -147,9 +154,9 @@ tomllib.loads("['This parses fine with Python 3.6+']")
147154
148155- it's lil'
149156- pure Python with zero dependencies
150- - the fastest pure Python parser [ \* ] ( #performance ) :
151- 16x as fast as [ tomlkit] ( https://pypi.org/project/tomlkit/ ) ,
152- 2.3x as fast as [ toml] ( https://pypi.org/project/toml/ )
157+ - the fastest pure Python parser [ \* ] ( #pure-python ) :
158+ 18x as fast as [ tomlkit] ( https://pypi.org/project/tomlkit/ ) ,
159+ 2.1x as fast as [ toml] ( https://pypi.org/project/toml/ )
153160- outputs [ basic data types] ( #how-do-toml-types-map-into-python-types ) only
154161- 100% spec compliant: passes all tests in
155162 [ BurntSushi/toml-test] ( https://github.com/BurntSushi/toml-test )
@@ -193,30 +200,48 @@ The core library does not include write capability, as most TOML use cases are r
193200## Performance<a name =" performance " ></a >
194201
195202The ` benchmark/ ` folder in this repository contains a performance benchmark for comparing the various Python TOML parsers.
196- The benchmark can be run with ` tox -e benchmark-pypi ` .
197- Running the benchmark on my personal computer output the following:
203+
204+ Below are the results for commit [ 0724e2a] ( https://github.com/hukkin/tomli/tree/0724e2ab1858da7f5e05a9bffdb24c33589d951c ) .
205+
206+ ### Pure Python<a name =" pure-python " ></a >
198207
199208``` console
200- foo@bar:~/dev/tomli $ tox -e benchmark-pypi
201- benchmark-pypi installed: attrs==21.4.0,click==8.0.3,pytomlpp==1.0.10,qtoml==0.3.1,rtoml==0.7.1,toml==0.10.2,tomli==2.0.1,tomlkit==0.9.2
202- benchmark-pypi run-test-pre: PYTHONHASHSEED='3088452573'
203- benchmark-pypi run-test: commands[0] | python -c 'import datetime; print(datetime.date.today())'
204- 2022-02-09
205- benchmark-pypi run-test: commands[1] | python --version
206- Python 3.8.10
207- benchmark-pypi run-test: commands[2] | python benchmark/run.py
209+ foo@bar:~/dev/tomli $ python --version
210+ Python 3.12.7
211+ foo@bar:~/dev/tomli $ pip freeze
212+ attrs==21.4.0
213+ click==8.1.7
214+ pytomlpp==1.0.13
215+ qtoml==0.3.1
216+ rtoml==0.11.0
217+ toml==0.10.2
218+ tomli @ file:///home/foo/dev/tomli
219+ tomlkit==0.13.2
220+ foo@bar:~/dev/tomli $ python benchmark/run.py
208221Parsing data.toml 5000 times:
209222------------------------------------------------------
210223 parser | exec time | performance (more is better)
211224-----------+------------+-----------------------------
212- rtoml | 0.891 s | baseline (100%)
213- pytomlpp | 0.969 s | 91.90 %
214- tomli | 4 s | 22.25 %
215- toml | 9.01 s | 9.88 %
216- qtoml | 11.1 s | 8.05 %
217- tomlkit | 63 s | 1.41 %
225+ rtoml | 0.647 s | baseline (100%)
226+ pytomlpp | 0.891 s | 72.62 %
227+ tomli | 3.14 s | 20.56 %
228+ toml | 6.69 s | 9.67 %
229+ qtoml | 8.27 s | 7.82 %
230+ tomlkit | 56.1 s | 1.15 %
218231```
219232
220- The parsers are ordered from fastest to slowest, using the fastest parser as baseline.
221- Tomli performed the best out of all pure Python TOML parsers,
222- losing only to pytomlpp (wraps C++) and rtoml (wraps Rust).
233+ ### Mypyc generated wheel<a name =" mypyc-generated-wheel " ></a >
234+
235+ ``` console
236+ foo@bar:~/dev/tomli $ python benchmark/run.py
237+ Parsing data.toml 5000 times:
238+ ------------------------------------------------------
239+ parser | exec time | performance (more is better)
240+ -----------+------------+-----------------------------
241+ rtoml | 0.668 s | baseline (100%)
242+ pytomlpp | 0.893 s | 74.81%
243+ tomli | 1.96 s | 34.18%
244+ toml | 6.64 s | 10.07%
245+ qtoml | 8.26 s | 8.09%
246+ tomlkit | 52.9 s | 1.26%
247+ ```
0 commit comments