Home

Awesome

json_benchmark

<!-- start_last_updated_block -->

:grey_exclamation: Benchmarks regenerated on 2023-09-05

<!-- end_last_updated_block -->

This repository contains benchmarks for Python JSON readers & writers. What's the fastest Python JSON parser? Let's find out.

To run the tests yourself:

git clone git@github.com:TkTech/json_benchmark.git && cd json_benchmark
<setup a virtualenv using your tool of choice>
poetry install
pytest --benchmark-json benchmark.json --benchmark-histogram histograms/

To update the tables in the README.md with the new results, just run:

python generate_benchmark_summaries.py
python generate_minefield_reports.py

Candidate Libraries

The following libraries are the current candidates for benchmarking. Feel free to request or add new libraries.

LibraryReaderWriterVersion
simdjsonYesNo6.0.0
cysimdjsonYesNo23.9
yyjsonYesYes2.3.1
orjsonYesYes3.9.5
rapidjsonYesYes1.10
ujsonYesYes5.8.0
jsonYesYes3.11
msgspecYesYes0.18.2

Correctness

cd It doesn't matter how fast a JSON parser is if it's not going to give you the correct results. We run the JSON minefield against each library. To see the complete line-by-line results, see the <minefield_reports/> directory.

<!-- start_correct_block -->

yyjson

See full minefield results for yyjson.

countresult
283🎉 expected result
0🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
6âž• result undefined, parsing succeeded
29âž– result undefined, parsing failed

rapidjson

See full minefield results for rapidjson.

countresult
277🎉 expected result
6🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
6âž• result undefined, parsing succeeded
29âž– result undefined, parsing failed

orjson

See full minefield results for orjson.

countresult
283🎉 expected result
0🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
6âž• result undefined, parsing succeeded
29âž– result undefined, parsing failed

simdjson

See full minefield results for simdjson.

countresult
283🎉 expected result
0🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
3âž• result undefined, parsing succeeded
32âž– result undefined, parsing failed

ujson

See full minefield results for ujson.

countresult
267🎉 expected result
16🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
21âž• result undefined, parsing succeeded
14âž– result undefined, parsing failed

msgspec

See full minefield results for msgspec.

countresult
283🎉 expected result
0🔥 parsing should have failed but succeeded
0🔥 parsing should have succeeded but failed
6âž• result undefined, parsing succeeded
29âž– result undefined, parsing failed
<!-- end_correct_block -->

Performance

In these benchmarks, lower is better.

<!-- start_performance_block -->

Complete load of data/canada.json

Sample file is 2251051 bytes.

librarymin (ms)max (ms)mean (ms)
orjson5.001914.19279.6857
simdjson5.821418.148311.5799
msgspec5.902716.110410.1492
cysimdjson5.969614.71029.1315
yyjson6.117521.275212.7247
ujson10.171424.248116.5537
json21.631430.139626.0608
rapidjson23.499934.453329.2562

Complete load of data/citm_catalog.json

Sample file is 1727030 bytes.

librarymin (ms)max (ms)mean (ms)
orjson2.251112.91073.9478
yyjson2.701717.01225.3347
simdjson2.878515.33785.0631
msgspec2.945913.91664.5182
cysimdjson3.02518.79564.0554
rapidjson4.761215.97536.7336
ujson4.849719.44237.4472
json4.964711.90166.2808

Complete load of data/twitter.json

Sample file is 567916 bytes.

librarymin (ms)max (ms)mean (ms)
orjson0.82549.29970.9887
yyjson0.911513.41721.1653
simdjson0.970811.74511.1930
msgspec1.062110.10931.2256
cysimdjson1.35257.06231.4850
rapidjson2.015612.05042.2450
json2.10439.72672.2753
ujson2.201514.44912.4740

Complete load of data/verysmall.json

Sample file is 7 bytes.

librarymin (ms)max (ms)mean (ms)
msgspec0.00010.00030.0001
orjson0.00010.00030.0001
simdjson0.00020.00080.0002
ujson0.00020.00110.0003
rapidjson0.00030.00150.0003
yyjson0.00030.00140.0003
cysimdjson0.00030.00090.0003
json0.00070.00190.0007

Merge Patch

librarymin (ms)max (ms)mean (ms)
yyjson0.00040.00100.0004
json_merge_patch0.00040.00270.0005
<!-- end_performance_block -->

FAQ

Why doesn't this run benchmarks using Github Actions?

Generally, unless you control the CI runners with self-hosted boxes (which are unsafe on public Github projects!), you have no idea what machine you're going to get, or how many other jobs may be running on the same machine. This can cause the benchmarks to vary drastically between runs, even minutes apart. For this reason benchmarks are always run locally on a consistent machine, in a consistent state.

What machine is used for the x64 benchmarks?

x64 tests are run on an AMD Ryzen 7 5800X, capped at base clock speed with 64GB of Corsair CMW32GX4M2E3200C16.

JSON is terrible, use X!

This repository isn't for arguing the pros or cons of JSON versus some other exchange format. You frequently have no choice but to work with JSON, and if you can read or write responses 15% faster, that means you can handle more requests per second with the same hardware.