Performance¶
This library is written in Cython for a better performance than a pure-Python implementation could give you.
Decoder Performance¶
The library is a bit slower than the shipped json
module for pure JSON data.
If you know that your input does not use JSON5 extension, then this library is probably not what you need.
Version: Python 3.7.5 (default, Oct 27 2019, 15:43:29)
CPU: AMD Ryzen 7 2700 @ 3.7GHz
pyjson5.decode()
: 3.18 s ± 4.89 ms per loop per loop per loop (lower is better)json.loads()
: 2.64 s ± 12.7 ms ms per loopThe 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 pyjson5.encode()
or pyjson5.encode_bytes()
.
Version: Python 3.7.5 (default, Oct 27 2019, 15:43:29)
CPU: AMD Ryzen 7 2700 @ 3.7GHz
pyjson5.encode()
: 3.42 s ± 11.8 ms per loop (lower is better)json.dumps()
: 3.77 s ± 14.4 ms per loopjson.dumps()
+xml.sax.saxutils.escape()
: 4.02 s ± 51.6 ms per loopThe encoder works correcty:
obj == json.loads(pyjson5.encode(obj, floatformat='%.16e'))