The ssrJSON benchmark repository.
The benchmark results can be found in website results or GitHub results. Contributing your benchmark result is welcomed.
Quick jump for
# you may need to install `svglib`, `reportlab` and `py-cpuinfo` as well
pip install ssrjson-benchmark
python -m ssrjson_benchmark-moutput in Markdown instead of PDF.-f <json_path>used exists benchmark json result.--process-bytes <bytes_num>Total process bytes per test, default 1e8.
- This repository conducts benchmarking using json, orjson, ujson, and ssrJSON. The
dumpsbenchmark produces str objects, comparing three operations:json.dumps,orjson.dumpsfollowed by decode, andssrjson.dumps. Thedumps_to_bytesbenchmark produces bytes objects, comparing three functions:json.dumpsfollowed by encode,orjson.dumps, andssrjson.dumps_to_bytes. - When orjson handles non-ASCII strings, if the cache of the
PyUnicodeObject’s UTF-8 representation does not exist, it invokes thePyUnicode_AsUTF8AndSizefunction to obtain the UTF-8 encoding. This function then caches the UTF-8 representation within thePyUnicodeObject. If the samePyUnicodeObjectundergoes repeated encode-decode operations, subsequent calls after the initial one will execute more quickly due to this caching. However, in real-world production scenarios, it is uncommon to perform JSON encode-decode repeatedly on the exact same string object; even identical strings are unlikely to be the same object instance. To achieve benchmark results that better reflect practical use cases, we employssrjson.run_unicode_accumulate_benchmarkandbenchmark_invalidate_dump_cachefunctions, which ensure that newPyUnicodeObjects are different for each input every time. (ref: orjson#586) - The performance of JSON encoding is primarily constrained by the speed of writing to the buffer, whereas decoding performance is mainly limited by the frequent invocation of CPython interfaces for object creation. During decoding, both ssrJSON and orjson employ short key caching to reduce the number of object creations, and this caching mechanism is global in both cases. As a result, decoding benchmark tests may not accurately reflect the conditions encountered in real-world production environments.
- The files simple_object.json and simple_object_zh.json do not represent real-world data; they are solely used to compare the performance of the fast path. Therefore, the benchmark results should not be interpreted as indicative of actual performance.