Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Comprehensive performance comparison between all json2xml implementations.

- **Machine**: Apple Silicon (M-series, aarch64)
- **OS**: macOS
- **Date**: January 28, 2026
- **Date**: March 12, 2026

### Implementations Tested

Expand All @@ -22,32 +22,32 @@ Comprehensive performance comparison between all json2xml implementations.
| Size | Description | Bytes |
|------|-------------|-------|
| Small | Simple object `{"name": "John", "age": 30, "city": "New York"}` | 47 |
| Medium | 10 generated records with nested structures | ~3,208 |
| Medium | 10 generated records with nested structures | ~3,211 |
| bigexample.json | Real-world patent data | 2,018 |
| Large | 100 generated records with nested structures | ~32,205 |
| Very Large | 1,000 generated records with nested structures | ~323,119 |
| Large | 100 generated records with nested structures | ~32,220 |
| Very Large | 1,000 generated records with nested structures | ~323,114 |

## Results

### Performance Summary

| Test Case | Python | Rust | Go | Zig |
|-----------|--------|------|-----|-----|
| Small (47B) | 41.88µs | 1.66µs | 4.52ms | 2.80ms |
| Medium (3.2KB) | 2.19ms | 71.85µs | 4.33ms | 2.18ms |
| bigexample (2KB) | 854.38µs | 30.89µs | 4.28ms | 2.12ms |
| Large (32KB) | 21.57ms | 672.96µs | 4.47ms | 2.48ms |
| Very Large (323KB) | 216.52ms | 6.15ms | 4.44ms | 5.54ms |
| Small (47B) | 78.39µs | 1.05µs | 4.31ms | 1.96ms |
| Medium (3.2KB) | 2.15ms | 15.47µs | 5.03ms | 2.34ms |
| bigexample (2KB) | 862.12µs | 6.44µs | 4.47ms | 2.38ms |
| Large (32KB) | 22.08ms | 150.91µs | 4.80ms | 2.89ms |
| Very Large (323KB) | 218.63ms | 1.47ms | 4.75ms | 5.38ms |

### Speedup vs Pure Python

| Test Case | Rust | Go | Zig |
|-----------|------|-----|-----|
| Small (47B) | **25.2x** | 0.0x* | 0.0x* |
| Medium (3.2KB) | **30.5x** | 0.5x* | 1.0x* |
| bigexample (2KB) | **27.7x** | 0.2x* | 0.4x* |
| Large (32KB) | **32.1x** | 4.8x | **8.7x** |
| Very Large (323KB) | **35.2x** | **48.8x** | **39.1x** |
| Small (47B) | **74.9x** | 0.0x* | 0.0x* |
| Medium (3.2KB) | **139.1x** | 0.4x* | 0.9x* |
| bigexample (2KB) | **133.9x** | 0.2x* | 0.4x* |
| Large (32KB) | **146.3x** | 4.6x | **7.6x** |
| Very Large (323KB) | **149.2x** | **46.1x** | **40.6x** |

*CLI tools have process spawn overhead (~2-4ms) which dominates for small inputs

Expand All @@ -56,23 +56,23 @@ Comprehensive performance comparison between all json2xml implementations.
### 1. Rust Extension is the Best Choice for Python Users 🦀

The Rust extension (json2xml-rs) provides:
- **~25-35x faster** than pure Python consistently across all input sizes
- **~75-149x faster** than pure Python consistently across all input sizes
- **Zero process overhead** - called directly from Python
- **Automatic fallback** - pure Python used if Rust unavailable
- **Easy install**: `pip install json2xml[fast]`

### 2. Go Excels for Very Large CLI Workloads 🚀

For very large inputs (323KB+):
- **48.8x faster** than Python
- **46.1x faster** than Python
- But ~4ms startup overhead hurts small file performance
- Best for batch processing or large file conversions

### 3. Zig is Now Highly Competitive ⚡

After recent optimizations:
- **39.1x faster** than Python for very large files
- **8.7x faster** for large files (32KB)
- **40.6x faster** than Python for very large files
- **7.6x faster** for large files (32KB)
- Faster startup than Go (~2ms vs ~4ms)
- Best balance of startup time and throughput

Expand All @@ -89,7 +89,7 @@ CLI tools (Go, Zig) have process spawn overhead:

| Use Case | Recommended | Why |
|----------|-------------|-----|
| Python library calls | **Rust** (`pip install json2xml[fast]`) | 25-35x faster, no overhead |
| Python library calls | **Rust** (`pip install json2xml[fast]`) | 75-149x faster, no overhead |
| Small files via CLI | **Zig** (json2xml-zig) | Fastest startup (~2ms) |
| Large files via CLI | **Go** or **Zig** | Both excellent (Go slightly faster) |
| Batch processing | **Go** or **Rust** | Both excellent |
Expand Down
30 changes: 15 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Installation

pip install json2xml

**With Native Rust Acceleration (28x faster)**
**With Native Rust Acceleration (up to 149x faster)**

For maximum performance, install the optional Rust extension:

Expand All @@ -55,7 +55,7 @@ For maximum performance, install the optional Rust extension:
# Or install the Rust extension separately
pip install json2xml-rs

The Rust extension provides **28x faster** conversion compared to pure Python. It's automatically used when available, with seamless fallback to pure Python.
The Rust extension provides **75-149x faster** conversion compared to pure Python. It's automatically used when available, with seamless fallback to pure Python.

**As a CLI Tool**

Expand Down Expand Up @@ -301,7 +301,7 @@ Using tools directly:

**Rust Extension Development**

The optional Rust extension (``json2xml-rs``) provides 29x faster performance. To develop or build the Rust extension:
The optional Rust extension (``json2xml-rs``) provides up to 149x faster performance. To develop or build the Rust extension:

Prerequisites:

Expand Down Expand Up @@ -428,21 +428,21 @@ For users who need maximum performance within Python, json2xml includes an optio
- Rust Extension
- Speedup
* - **Small JSON** (47 bytes)
- 40µs
- 1.5µs
- **27x**
- 78µs
- 1.05µs
- **75x**
* - **Medium JSON** (3.2 KB)
- 2.1ms
- 71µs
- **30x**
- 2.15ms
- 15µs
- **139x**
* - **Large JSON** (32 KB)
- 21ms
- 740µs
- **28x**
- 22ms
- 151µs
- **146x**
* - **Very Large JSON** (323 KB)
- 213ms
- 7.5ms
- **28x**
- 219ms
- 1.47ms
- **149x**

**Usage with Rust Extension:**

Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json2xml_rs"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "Fast native JSON to XML conversion for Python"
license = "Apache-2.0"
Expand All @@ -14,7 +14,7 @@ default = ["python"]
python = ["pyo3/extension-module", "dep:pyo3"]

[dependencies]
pyo3 = { version = "0.27", optional = true }
pyo3 = { version = "0.28.2", optional = true }

[profile.release]
lto = true
Expand Down
2 changes: 1 addition & 1 deletion rust/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "json2xml_rs"
version = "0.1.0"
version = "0.2.0"
description = "Fast native JSON to XML conversion - Rust extension for json2xml"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
Loading
Loading