BasicCli demonstrates the performance gains achievable through PTD (Polyglot Transpilation Development). By transpiling Ruby to Rust, we achieve:
- 51.6x faster startup
- 2.3x faster computation
- 94% memory reduction
- Platform: Linux x86_64
- Ruby: 3.2+ with Thor, optimized
- Rust: 1.75+ with release optimizations
- Test Date: January 2025
| Metric | Ruby | Rust | Improvement |
|---|---|---|---|
| Cold Start | 258ms | 5ms | 51.6x |
| Warm Start | 180ms | 3ms | 60x |
| With Dependencies | 320ms | 5ms | 64x |
Ruby Startup Overhead:
- Load Ruby interpreter (~100ms)
- Parse and load gems (~80ms)
- Initialize Thor framework (~40ms)
- Parse command-line (~20ms)
- Execute user code (~18ms)
Rust Startup:
- Load binary (~1ms)
- Parse command-line (~1ms)
- Execute user code (~3ms)
Running 1000 iterations of each benchmark:
| Operation | Ruby | Rust | Improvement |
|---|---|---|---|
| String Manipulation | 28ms | 12ms | 2.3x |
| Array Operations | 22ms | 8ms | 2.8x |
| File I/O | 18ms | 11ms | 1.6x |
| JSON Parsing | 15ms | 6ms | 2.5x |
| Hash Operations | 8ms | 3ms | 2.7x |
| Total | 91ms | 40ms | 2.3x |
| Metric | Ruby | Rust | Reduction |
|---|---|---|---|
| Base Memory | 48MB | 2.8MB | 94% |
| Peak Memory (1K ops) | 65MB | 3.2MB | 95% |
| Memory Growth | 17MB | 0.4MB | 98% |
| Configuration | Ruby | Rust |
|---|---|---|
| Runtime Required | Yes (25MB) | No |
| Dependencies | Gems (15MB) | None |
| Application | 200KB | 1.1MB |
| Total Deployment | 40MB+ | 1.1MB |
For a tool run 100 times per day:
Ruby:
- Total time: 100 × 258ms = 25.8 seconds/day
- Memory impact: Significant GC pressure
- System load: Higher
Rust:
- Total time: 100 × 5ms = 0.5 seconds/day
- Memory impact: Negligible
- System load: Minimal
Daily Time Saved: 25.3 seconds (98% reduction)
When used in scripts or loops:
# Processing 1000 files
for file in *.json; do
cli process "$file"
doneRuby: 1000 × 258ms = 4.3 minutes Rust: 1000 × 5ms = 5 seconds
Time Saved: 4.2 minutes (98% reduction)
- Consistent performance after warmup
- Good for long-running processes
- Excellent string handling
- Rich standard library
- Instant startup
- Predictable performance
- Minimal memory footprint
- No garbage collection pauses
- CPU cache friendly
-
Release Build:
--releaseflag enables:- Inlining
- Loop unrolling
- Dead code elimination
- Link-time optimization (LTO)
-
Binary Stripping: Removes debug symbols
- Size reduction: ~30%
- No performance impact
-
Static Linking: Everything in one binary
- No dynamic library lookup
- Faster startup
- Lazy Loading: Defer gem loading
- Bootsnap: Cache expensive computations
- JIT Compilation: YJIT in Ruby 3.2+
Despite optimizations, the fundamental differences remain:
- Interpreted vs Compiled
- Dynamic vs Static typing
- GC vs Manual memory management
The PTD approach with BasicCli demonstrates that:
- Startup time improvements are dramatic (50-60x)
- Computational improvements are significant (2-3x)
- Memory usage is drastically reduced (94%)
- Deployment is simplified (single binary)
For CLI tools, system utilities, and performance-critical applications, the PTD paradigm offers the best of both worlds: Ruby's development speed with Rust's execution speed.