Skip to content

Latest commit

 

History

History
283 lines (217 loc) · 8.83 KB

File metadata and controls

283 lines (217 loc) · 8.83 KB

🏁 command-stream Benchmark Suite

Comprehensive benchmarking suite that compares command-stream against all major competitors with concrete performance data to justify switching from alternatives.

📊 Overview

This benchmark suite provides concrete performance data to help developers make informed decisions when choosing a shell utility library. We compare command-stream against:

  • execa (98M+ monthly downloads) - Modern process execution
  • cross-spawn (409M+ monthly downloads) - Cross-platform spawning
  • ShellJS (35M+ monthly downloads) - Unix shell commands
  • zx (4.2M+ monthly downloads) - Google's shell scripting
  • Bun.$ (built-in) - Bun's native shell

🎯 Benchmark Categories

1. 📦 Bundle Size Analysis

Goal: Compare bundle sizes and dependency footprints

  • Installed size comparison
  • Gzipped bundle size estimates
  • Dependency count analysis
  • Tree-shaking effectiveness
  • Memory footprint at runtime

Key Metrics:

  • command-stream: ~20KB gzipped
  • Competitors: 2KB-400KB+ range
  • Zero dependencies vs heavy dependency trees

2. ⚡ Performance Benchmarks

Goal: Measure execution speed and resource usage

Test Categories:

  • Process Spawning Speed - How fast commands start
  • Streaming vs Buffering - Memory efficiency with large outputs
  • Pipeline Performance - Multi-command pipeline speed
  • Concurrent Execution - Parallel process handling
  • Error Handling Speed - Exception and error code performance
  • Memory Usage Patterns - Heap usage during operations

Key Measurements:

  • Average execution time (ms)
  • Memory delta during operations
  • 95th/99th percentile performance
  • Throughput for streaming operations

3. 🧪 Feature Completeness Tests

Goal: Validate API compatibility and feature parity

Test Areas:

  • Template Literal Support - $`command` syntax
  • Real-time Streaming - Live output processing
  • Async Iteration - for await loop support
  • EventEmitter Pattern - .on() event handling
  • Built-in Commands - Cross-platform command availability
  • Pipeline Support - Command chaining capabilities
  • Signal Handling - SIGINT/SIGTERM management
  • Mixed Patterns - Combining different usage styles

Compatibility Matrix:

  • ✅ Full support
  • 🟡 Limited support
  • ❌ Not supported

4. 🌍 Real-World Use Cases

Goal: Test realistic scenarios and workflows

Scenarios Tested:

  • CI/CD Pipeline Simulation - Typical build/test/deploy workflows
  • Log Processing - Analyzing large log files with grep/awk
  • File Operations - Batch file processing and organization
  • Development Workflows - Common dev tasks like finding files, counting lines
  • Network Command Handling - Connectivity checks and remote operations

Measurements:

  • End-to-end workflow performance
  • Error resilience in production scenarios
  • Resource usage under realistic loads

🚀 Quick Start

Run All Benchmarks

# Complete benchmark suite (may take 5-10 minutes)
npm run benchmark

# Quick benchmark (features + performance only)
npm run benchmark:quick

Run Individual Suites

# Bundle size comparison
npm run benchmark:bundle

# Performance tests
npm run benchmark:performance  

# Feature completeness tests
npm run benchmark:features

# Real-world scenarios
npm run benchmark:real-world

Manual Execution

cd benchmarks

# Run specific benchmark
node bundle-size/bundle-size-benchmark.mjs
node performance/performance-benchmark.mjs  
node features/feature-completeness-benchmark.mjs
node real-world/real-world-benchmark.mjs

# Run comprehensive suite with options
node run-all-benchmarks.mjs --skip-bundle-size --skip-real-world

📋 Results & Reports

Generated Reports

After running benchmarks, check the benchmarks/results/ directory:

  • comprehensive-benchmark-report.html - Interactive HTML report
  • comprehensive-results.json - Complete raw data
  • Individual JSON files - Detailed results for each suite
  • Charts and visualizations - Performance comparisons

Understanding Results

Performance Rankings:

  • 🥇 1st place - Fastest implementation
  • 🥈 2nd place - Good performance
  • 🥉 3rd place - Acceptable performance
  • Speed ratios show relative performance (1.00x = baseline)

Feature Test Results:

  • PASS - Feature works correctly
  • FAIL - Feature missing or broken
  • Success rate shows overall compatibility

Bundle Size Rankings:

  • Ranked by gzipped size (smaller = better)
  • Includes dependency impact
  • Memory usage estimates

🔧 Configuration

Environment Variables

# Enable verbose logging
export COMMAND_STREAM_VERBOSE=true

# Run in CI mode
export CI=true

Customizing Benchmarks

Edit benchmark files to adjust:

  • Iteration counts - More iterations = more accurate results
  • Warmup rounds - Reduce JIT compilation effects
  • Test data sizes - Adjust for your use case
  • Timeout values - Prevent hanging on slow systems

Adding New Competitors

To benchmark against additional libraries:

  1. Install the competitor: npm install competitor-lib
  2. Add implementation in relevant benchmark file
  3. Update feature matrix in features/feature-completeness-benchmark.mjs

🤖 CI Integration

GitHub Actions

The benchmark suite runs automatically:

  • On Pull Requests - Smoke tests + comparison with main branch
  • On Main Branch - Full benchmark suite
  • Weekly Schedule - Regression testing
  • Manual Trigger - On-demand with custom options

Benchmark Regression Detection

  • Compares PR results with main branch baseline
  • Alerts on significant performance regressions
  • Tracks feature test success rate changes
  • Generates comparison reports

CI Commands

# Trigger benchmarks in PR (add to title)
[benchmark] Your PR title

# Manual workflow dispatch with options
# Use GitHub Actions UI to customize which suites run

📈 Performance Optimization

Best Practices Tested

  • Streaming vs Buffering - When to use each approach
  • Concurrent vs Sequential - Optimal parallelization patterns
  • Memory Management - Preventing memory leaks in long-running processes
  • Error Handling - Fast vs robust error management strategies

Optimization Insights

The benchmarks reveal:

  • Stream processing is 2-5x more memory efficient for large data
  • Built-in commands avoid process spawning overhead
  • Concurrent execution scales well up to CPU core count
  • Event patterns add minimal overhead vs direct awaiting

🔍 Troubleshooting

Common Issues

Timeouts:

  • Increase timeout values for slow systems
  • Skip heavy benchmark suites with --skip-* flags

Memory Issues:

  • Use streaming benchmarks on systems with limited RAM
  • Enable garbage collection with --expose-gc flag

Permission Errors:

  • Ensure write access to benchmarks/results/ directory
  • Some tests create temporary files in /tmp/

Missing Dependencies:

  • Install system tools: jq, curl, grep, awk
  • Ensure Bun/Node.js versions meet requirements

Debug Mode

# Enable verbose logging for debugging
COMMAND_STREAM_VERBOSE=true npm run benchmark:features

# Run single test for debugging
cd benchmarks
node -e "
import('./features/feature-completeness-benchmark.mjs')
  .then(m => new m.default())
  .then(b => b.testBasicExecution())
  .then(console.log)
"

🏆 Success Metrics

The benchmark suite validates that command-stream provides:

✅ Performance Advantages

  • Faster streaming than buffered alternatives
  • Lower memory usage for large data processing
  • Competitive process spawning speed
  • Efficient concurrent execution

✅ Bundle Size Benefits

  • Smaller footprint than feature-equivalent alternatives
  • Zero runtime dependencies
  • Tree-shaking friendly modular architecture

✅ Feature Completeness

  • 90%+ feature test success rate
  • Unique capabilities not available in competitors
  • Cross-platform compatibility
  • Runtime flexibility (Bun + Node.js)

✅ Real-World Validation

  • Production-ready performance in CI/CD scenarios
  • Reliable error handling under stress
  • Developer workflow optimization

📚 Additional Resources


🌟 Help us improve! If you find issues with the benchmarks or have suggestions for additional tests, please open an issue or submit a PR.