copyleftdev/bench-press
The Great Rust vs TypeScript vs C vs Zig Performance Battle
Welcome to the most entertaining performance benchmark you'll ever see! This repository chronicles an epic battle between Rust, TypeScript, C, and Zig, where we pushed all languages to their absolute limits and beyond.
Spoiler Alert: Zig achieved 417 MILLION events/sec and is the new champion! ⚡👑
What started as a simple streaming JSON pipeline benchmark turned into an optimization arms race that would make Formula 1 engineers jealous.
The benchmark evaluates a streaming JSON pipeline that processes events through four stages:
# Clone the repository
git clone <repository-url>
cd bench-rust-ts
# Install Rust dependencies
cargo build --release
# Install TypeScript dependencies
npm install
# Run the complete benchmark suite (Rust, TypeScript, C, Zig)
./run_all_languages.sh
# Each run produces a comprehensive report showing:
# - Round-by-round performance comparison
# - Live throughput measurements
# - Final performance leaderboard
# - Epic battle narrative with results
# Run individual implementations
cargo run --release -- --batch-size 1000 --num-events 10000
node benchmarks/typescript/simple-ts-bench.cjs
./benchmarks/c/extreme_c_bench 1000 10000
./benchmarks/zig/zig-out/bin/extreme_zig_bench 1000 10000
npx tsx src/main.ts
BATCH_SIZE
: Number of events per batch (default: 1000)WINDOW_MS
: Window size in milliseconds (default: 1000)NUM_EVENTS
: Total number of events to process (default: 100000)NUM_WORKERS
: Number of worker threads (default: 4)SEED
: Random seed for reproducibility (default: 42)--batch-size
: Number of events per batch--window-ms
: Window size in milliseconds--num-events
: Total number of events to process--seed
: Random seed for reproducibility--verbose
: Enable verbose logging./run_all_languages.sh
)Each run produces a comprehensive report like this:
🥇 Rank | Implementation | Performance | Status |
---|---|---|---|
⚡ 1st | Extreme Zig | 417M events/sec | 👑 CHAMPION! |
🚀 2nd | Nuclear Rust | 378M events/sec | 🥈 STRONG |
🔥 3rd | Extreme C | 343M events/sec | 🥉 BRONZE |
4th | Ultimate Rust | 60M events/sec | Impressive |
5th | Maximum TypeScript | 4.7M events/sec | Valiant |
6th | Ultra-Optimized TypeScript | 1.5M events/sec | Strong |
7th | Optimized Rust | 715K events/sec | Solid |
8th | Original TypeScript | 238K events/sec | Good |
9th | Original Rust | 187K events/sec | Humble start |
Every execution of ./run_all_languages.sh
produces:
Sample Output:
🎬 Welcome to the ULTIMATE Performance Battle!
🦀 Rust vs 🟦 TypeScript vs 🔥 C vs ⚡ Zig
🥊 ROUND 1: The Humble Beginnings
🦀 Original Rust: 187K events/sec
🟦 Original TypeScript: 238K events/sec
🥊 FINAL ROUND: Nuclear Devastation
⚡ Extreme Zig: 417M events/sec (👑 NEW CHAMPION!)
🚀 Nuclear Rust: 378M events/sec (🥈 STRONG CONTENDER)
🔥 Extreme C: 343M events/sec (🥉 BRONZE MEDAL)
📊 Final Performance Summary:
- Extreme Zig: ~417M events/sec (👑 NEW CHAMPION!)
- Nuclear Rust: ~378M events/sec (🥈 STRONG CONTENDER)
- Extreme C: ~343M events/sec (🥉 BRONZE MEDAL)
...
Event Stream → Decode → Transform → Index → Aggregate → Results
↓ ↓ ↓ ↓ ↓ ↓
Batches Events Enriched Terms Metrics Reports
bench-rust-ts/
├── src/
│ ├── types.rs/ts # Shared data structures
│ ├── index.rs/ts # Inverted index implementation
│ ├── aggregator.rs/ts # Windowed aggregation
│ ├── generator.rs/ts # Event generation
│ ├── pipeline.rs/ts # Processing pipeline
│ └── main.rs/ts # Entry points
├── Cargo.toml # Rust dependencies
├── package.json # TypeScript dependencies
└── benchmark.sh # Benchmark runner
types
# Run Rust tests
cargo test
# Run TypeScript tests
npm test
# Run integration tests
./benchmark.sh --num-events 10000
cargo bench
for micro-benchmarksperf
or valgrind
node --prof
for CPU profiling--inspect
MIT License - see LICENSE file for details.