| Performance |
| =========== |
| |
| This library is written in Cython for a better performance than a pure-Python implementation could give you. |
| |
| |
| Decoder Performance |
| ------------------- |
| |
| The library has about the same speed as the shipped ``json`` module for *pure* JSON data. |
| |
| * Dataset: https://github.com/zemirco/sf-city-lots-json |
| * Version: Python 3.9.1+ (default, Feb 5 2021, 13:46:56) |
| * CPU: AMD Ryzen 7 2700 @ 3.7GHz |
| * :func:`pyjson5.decode`: **2.08 s** ± 7.49 ms per loop *(lower is better)* |
| * :func:`json.loads`: **2.71 s** ± 12.1 ms per loop |
| * The decoder works correcty: ``json.loads(content) == pyjson5.loads(content)`` |
| |
| |
| Encoder Performance |
| ------------------- |
| |
| The encoder generates pure JSON data if there are no infinite or NaN values in the input, which are invalid in JSON. |
| The serialized data is XML-safe, i.e. there are no cheverons ``<>``, ampersands ``&``, apostrophes ``'`` or control characters in the output. |
| The output is always ASCII regardless if you call :func:`pyjson5.encode` or :func:`pyjson5.encode_bytes`. |
| |
| * Dataset: https://github.com/zemirco/sf-city-lots-json |
| * Python 3.9.1+ (default, Feb 5 2021, 13:46:56) |
| * CPU: AMD Ryzen 7 2700 @ 3.7GHz |
| * :func:`pyjson5.encode`: **1.37** s ± 19.2 per loop *(lower is better)* |
| * :func:`json.dumps`: **3.66** s ± 72.6 ms per loop |
| * :func:`json.dumps` + :func:`xml.sax.saxutils.escape`: **4.01** s ± 21.3 ms per loop |
| * The encoder works correcty: ``obj == json.loads(pyjson5.encode(obj))`` |
| |
| |
| Benchmark |
| --------- |
| |
| Using `Ultrajson's benchmark <https://github.com/ultrajson/ultrajson/blob/197a7fd4d8bbf0a8355852017c8b25aab26b6777/tests/benchmark.py>`_ |
| you can tell for which kind of data PyJSON5 is fast, and for which data it is slow in comparison *(higher is better)*: |
| |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | | json | pyjson5 | ujson | orjson | |
| +===========================================================+=============+============+============+============+ |
| | **Array with 256 doubles** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 6,425 | 81,202 | 28,966 | 83,836 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 16,759 | 34,801 | 34,794 | 80,655 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Array with 256 strings** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 36,969 | 73,165 | 35,574 | 113,082 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 42,730 | 38,542 | 38,386 | 60,732 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Array with 256 UTF-8 strings** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 3,458 | 3,134 | 4,024 | 31,677 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 2,428 | 2,498 | 2,491 | 1,750 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Array with 256 True values** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 130,441 | 282,703 | 131,279 | 423,371 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 220,657 | 262,690 | 264,485 | 262,283 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Array with 256 dict{string, int} pairs** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 11,621 | 10,014 | 18,148 | 73,905 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 17,802 | 19,406 | 19,391 | 23,478 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Dict with 256 arrays with 256 dict{string, int} pairs** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 40 | 38 | 68 | 213 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 43 | 49 | 48 | 51 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Medium complex object** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 8,704 | 11,922 | 15,319 | 49,677 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 12,567 | 14,042 | 13,985 | 19,481 | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | **Complex object** | | | | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | encode | 672 | 909 | 731 | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| | decode | 462 | 700 | 700 | | |
| +-----------------------------------------------------------+-------------+------------+------------+------------+ |
| |
| * `ujson <https://github.com/ultrajson/ultrajson>`_ == 4.0.3.dev9 |
| * `orjson <https://github.com/ijl/orjson>`_ == 3.5.1 |