🏎️

Software Drag Race: C++ vs Fortran vs COBOL

Dave's Garage Episode 04 • Systems Engineering Analysis

Executive Summary

Evaluating Compiled Execution Efficiency

This interactive breakdown analyzes retired Microsoft systems engineer Dave Plummer's single-threaded Sieve of Eratosthenes benchmark. The test evaluates how compiler optimization backends, memory abstraction layers, and instruction set primitives impact raw computational throughput across three foundational compiled languages.

Prime Limit ($N$) 1,000,000 78,498 Expected Primes
Test Window 5.0 Seconds Fixed Non-Extendable
Peak Throughput 13,500 P/s C++ Bitwise Engine
Performance Delta ~50x C++ / Fortran vs COBOL

Quantitative Results & Compiler Sensitivity

The benchmark splits contenders into two performance tiers: systems-oriented languages operating near hardware limits (C++ and Fortran) and record-oriented domain languages (COBOL). Explore overall throughput and notice how Fortran's output changes radically based on compiler versions and optimization flags.

Overall Throughput Comparison (Passes/sec)

Higher is Better

C++ and Fortran deliver comparable peak execution speeds, whereas COBOL lags by ~98% due to runtime indexing overhead.

Fortran Toolchain Sensitivity Breakdown

GCC evolution yielded a +39.4% throughput boost from gfortran-7 to 11 on unchanged source code.

Interactive Mechanics

Memory Hierarchy & Cache Locality Simulator

Why does a 1-bit storage representation drastically outperform an 8-bit byte array despite requiring CPU instructions for bit-shifting and masking? Toggle between the two storage modes below to simulate CPU cache saturation and footprint dynamics for $N = 1,000,000$.

Select Storage Strategy:
Calculated Data Footprint 61.0 KB
L1 Data Cache (32 KB) Partial Fit (190%)

Primary working set spills out of L1 cache.

L2 Data Cache (512 KB) 100% Residency (12%)

Entire dataset fits comfortably within high-speed L2 cache.

Execution Penalty 0% (Optimal)

Bitfield math is executed in single-cycle ALU operations.

Architectural Takeaway: Modern CPUs possess hyper-fast ALUs that can perform bit-shifting (`>>`), masking (`&`), and bitwise OR (`|`) operations in 1 clock cycle. The memory stall latency of fetching byte arrays from lower cache tiers or RAM costs up to 100x more cycles than doing the extra bitwise math.

Language Paradigm & Architectural Foundations

Select a language tab below to explore its historical focus, memory abstraction capabilities, hardware instruction mapping, and key bottlenecks during prime sieve computations.

Core Paradigms & Strengths

  • ✓Zero-Overhead Abstraction: Language constructs map directly to physical machine instructions without mandatory runtime checks.
  • ✓Native Bit Primitives: Full support for single-cycle bitwise operators (`&`, `|`, `~`, `^`, `<<`, `>>`).
  • ✓Inlined Memory Allocation: Minimal class encapsulation overhead with direct heap/stack pointer control.

Execution Mechanics in Sieve Benchmark

  • ℹPointer Aliasing Risk: Requires careful compiler flags or explicit restrict keywords to match Fortran's vectorization assumptions.
  • ℹCache Residency: Packed bitfield fits 100% inside CPU L2 cache, preventing pipeline stalls.
  • ℹThroughput Range: 10,000 – 13,500 Passes/sec.
Methodology

Benchmark Rules & Faithful Implementation Criteria

To maintain strict parity and prevent compiler optimization shortcuts (such as static array caching or precomputed prime tables), all submissions in the Dave's Garage Software Drag Race must adhere to standard rules.

01

Encapsulation Boundary

Algorithm must be encapsulated within a class, module, or object structure, preventing global scope pollution.

02

Dynamic Allocation

Working memory buffer must be re-allocated or re-initialized on every single pass rather than reusing static memory.

03

Truth Validation

Pass count and results must be verified against reference truth table (78,498 primes for $N=10^6$) upon completion.

04

Fixed Time Constraint

Executes for exactly 5.0 non-extendable seconds. Metric is total validated Passes per Second ($P/s$).

Engineering Takeaways: Microbenchmarks vs Reality

While microbenchmarks like the Sieve of Eratosthenes offer deep insight into integer ALU arithmetic, cache locality, and register allocation, they do not reflect complete language domain utility:

Scientific & Tensor Computing (Fortran)

In high-performance computational fluid dynamics or matrix algebra, Fortran's non-aliasing memory contracts allow vector compilers to achieve instruction pipelining and SIMD throughput that frequently surpasses C++.

Enterprise Transaction Processing (COBOL)

COBOL was designed to process streams of fixed-point financial records where IEEE floating-point binary rounding errors are illegal. Its syntax maps directly to hardware decimal arithmetic on modern enterprise mainframes.