JSONC Benchmark¶
Apple-to-apple performance comparison between zerodep JSONC and commentjson.
Test Environment
- CPU: x86_64 Linux
- Python: 3.12
- Tool: pytest-benchmark 5.2.3 (mean values reported)
- Reference: commentjson 0.9.0
- Last Updated: 2026-04-21
Implementations¶
| Implementation | File/Package | Description |
|---|---|---|
| zerodep | jsonc.py |
Regex-based comment stripping + stdlib json.loads |
| commentjson | (reference) | Lark LALR parser + AST reconstruction + stdlib json.loads |
Data Sizes Tested¶
| Label | Description |
|---|---|
| Small | 5-key object with // comments |
| Medium | Nested config (~40 lines) with //, # comments and trailing commas |
| Large | 100-item object with inline // comments and trailing commas |
Performance Comparison (Mean)¶
| Data Size | zerodep | commentjson | Speedup |
|---|---|---|---|
| Small | 15.5 us | 1,330.0 us | 86x faster |
| Medium | 96.4 us | 9,300.0 us | 97x faster |
| Large | 1,920.0 us | 217,820.0 us | 113x faster |
Key Takeaways¶
- 86--113x faster -- zerodep is dramatically faster across all data sizes, with the advantage increasing as input grows.
- Regex vs. LALR -- the performance gap comes from the approach: zerodep strips comments via lightweight regex then delegates to C-accelerated
json.loads, while commentjson builds a full parse tree using a Lark LALR parser before reconstructing the data. - Scales better -- the speedup ratio improves from 86x to 113x as data size increases, showing that the regex approach has much lower per-element overhead.
- Zero pip dependencies -- zerodep uses only
reandjsonfrom the standard library.
Run It Yourself¶
pip install pytest pytest-benchmark commentjson
pytest jsonc/test_jsonc_benchmark.py --benchmark-only -v
Latest CI Results¶
Updated automatically on each release via Benchmark CI.