Language Bench

A systematic performance benchmarking study comparing C++ and Rust

Overview

This project presents a systematic and reproducible performance comparison between C++ and Rust across a set of carefully designed benchmarks commonly used to evaluate system-level programming languages.

The objective is not to declare a universal “winner”, but to analyze execution performance, scalability, and runtime behavior under different workload characteristics using a consistent benchmarking methodology.

Each benchmark was executed multiple times, with average execution time and standard deviation recorded to capture both performance and run-to-run stability.

Benchmarks Implemented

The benchmarks progress from CPU-bound workloads to I/O-, string-, and memory-intensive operations:

  1. Summation Loop – Raw arithmetic and loop execution speed
  2. Branch-Heavy Loop – Branch prediction and control flow behavior
  3. Recursion Benchmark – Function call overhead and stack usage
  4. File Read – Sequential disk read throughput
  5. File Write – Sequential disk write performance
  6. String Parsing – Character-by-character parsing efficiency
  7. String Concatenation & Substring Search – Complex string manipulation
  8. Dynamic Allocation and Free – Heap allocation scalability
  9. Vector Insertion and Deletion – Dynamic container performance

Benchmarking Methodology

Large Workloads and Chunking

Extremely large workloads (hundreds of millions or billions of operations) cannot always be executed in a single allocation due to physical memory limits. In such cases, workloads were executed in fixed-size chunks while preserving the total operation count.

This maintains algorithmic equivalence while enabling realistic, scalable benchmarking.

Benchmark Results

Each benchmark includes visual comparisons for both large-scale and small-scale workloads.

1. Summation Loop

Measures raw arithmetic throughput and compiler optimization efficiency.

  • C++ performs better at mid-range workloads
  • Performance converges at extreme scales

2. Branch-Heavy Loop

Evaluates branch prediction and control-flow behavior.

  • Rust outperforms C++ for large branch-heavy workloads
  • Differences narrow at smaller scales

3. Fibonacci Recursion

Measures recursive function call overhead and stack management.

  • Rust scales better for deep recursion
  • C++ performs better at mid-range depths

4. File Read

Evaluates sequential disk read throughput.

  • Rust faster for large files
  • C++ faster for small files

5. File Write

Measures sequential disk write performance.

  • Rust excels at medium-sized writes
  • Differences shrink at small sizes

6. String Parsing

Evaluates large-scale text parsing workloads.

  • Rust significantly faster at large inputs
  • Advantage persists across scales

7. String Concatenation & Substring Search

Measures complex string growth and search operations.

  • Rust consistently outperforms C++
  • Performance gap widens with size

8. Dynamic Allocation and Free

Evaluates allocator scalability under heavy allocation pressure.

  • Rust scales better for large allocation counts
  • Performance converges at small counts

9. Vector Insertion and Deletion

Measures dynamic container performance.

  • Rust better for very large workloads
  • C++ marginally faster for small workloads

Benchmark Data

All benchmark measurements are published below for transparency and reproducibility. Summary results are shown first, followed by the complete raw dataset.

Summary Results

Raw Benchmark Data

System Configuration

Limitations

Future Enhancements

Repository

Source code, raw data, charts, and documentation:

github.com/ShaggyLenoo/language-bench