Skip to content

Performance benchmarks: C++ vs Rust for systems programming. RAII, lock-free data structures, async I/O, string processing. Reproducible methodology, <5% difference in most scenarios.

Notifications You must be signed in to change notification settings

cschladetsch/CppRustComparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ vs Rust Performance Comparison Suite

A rigorous, measurement-based comparison of fundamental systems programming patterns in C++20 and Rust (stable).

See full article.

Patterns Compared

Pattern C++ Approach Rust Approach
RAII Resource Management Smart pointers, RAII guards Drop trait, ownership
Lock-Free Ring Buffer std::atomic crossbeam/std::sync::atomic
Async I/O Pipeline C++20 coroutines tokio
Zero-Copy String Processing string_view, SSO &str slices, Cow

Project Structure

├── cpp/
│   ├── CMakeLists.txt          # Top-level CMake config
│   ├── raii/                   # RAII pattern
│   ├── ringbuffer/             # Lock-free ring buffer
│   ├── async_io/               # Async I/O pipeline
│   └── string_processing/      # Zero-copy strings
├── rust/
│   ├── Cargo.toml              # Workspace config
│   ├── raii/                   # RAII pattern
│   ├── ringbuffer/             # Lock-free ring buffer
│   ├── async_io/               # Async I/O pipeline
│   └── string_processing/      # Zero-copy strings
├── results/                    # Benchmark results
├── scripts/
│   ├── run_benchmarks.py       # Main runner
│   └── generate_report.py      # Report generator
└── README.md

Requirements

C++

  • CMake 3.20+
  • GCC 12+ or Clang 15+ (C++20 support)
  • Google Benchmark
  • Valgrind (memory profiling)
  • perf (Linux profiling)

Rust

  • Rust 1.75+ (stable)
  • Cargo

Analysis Tools

  • Python 3.10+
  • matplotlib, pandas, numpy

Building

C++

cd cpp
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)

Rust

cd rust
cargo build --release

Running Benchmarks

# Run all benchmarks
python scripts/run_benchmarks.py --all

# Run specific pattern
python scripts/run_benchmarks.py --pattern ringbuffer

# Generate comparison report
python scripts/generate_report.py

Methodology

  1. Warm-up: Each benchmark runs warm-up iterations to stabilize caches
  2. Statistical rigor: Multiple samples, outlier detection, confidence intervals
  3. Fair comparison: Same hardware, same workloads, same measurement methodology
  4. Idiomatic code: Each implementation follows language best practices

Hardware Specification

Benchmarks should be run on consistent hardware. Results include:

  • CPU model, cache sizes
  • RAM speed
  • OS/kernel version
  • Compiler versions

License

MIT

About

Performance benchmarks: C++ vs Rust for systems programming. RAII, lock-free data structures, async I/O, string processing. Reproducible methodology, <5% difference in most scenarios.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published