This repo compares how fast Python, C++, and Rust can parse JSON using various libraries. Same dataset, same schema, different languages—let’s see who wins!
We’re parsing a simple sensor data schema (details in the code) from an NDJSON file (messages.ndjson
) with 200,000 entries by default.
- Python:
json
,orjson
,msgspec
,rapidjson
- C++:
nlohmann/json
,RapidJSON
- Rust:
serde_json
,simd-json
Only deserialization (JSON to objects) is measured.
xlang-json-bench/
├─ data/generate.py # Makes the dataset
├─ python/bench.py # Python tests
├─ cpp/bench.cpp # C++ tests
├─ rust/ # Rust tests (Cargo.toml, src/main.rs)
├─ Dockerfile.* # One for each language
Generated by data/generate.py
. Tweak size with N
env var:
python data/generate.py --n 500000 --out messages.ndjson
Each language uses its own Docker setup:
# Python
docker build -f Dockerfile.python -t bench-python .
docker run --rm -e N=400000 bench-python
# C++
docker build -f Dockerfile.cpp -t bench-cpp .
docker run --rm -e N=400000 bench-cpp
# Rust
docker build -f Dockerfile.rust -t bench-rust .
docker run --rm -e N=400000 bench-rust
Throughput (items/second) for 400,000 items:
cpp nlohmann/json parse 712,808.0 items/s
cpp RapidJSON parse 3,207,240.0 items/s
py json.loads 704,572.4 items/s
py orjson.loads 2,865,668.9 items/s
py msgspec.json decode 2,835,611.0 items/s
py rapidjson.loads 932,406.5 items/s
rs serde_json parse 2,355,698.7 items/s
rs simd-json parse 2,522,190.0 items/s
- Dataset auto-generates on first run.
- Use
-e N=1000000
to change dataset size. - I/O is excluded for fair timing.
MIT License