Performance

Rust performance on Windows — LTO, PGO & release optimisation

Rust release builds are as fast as C++ and significantly faster than Go or Python. Enable LTO and set codegen-units = 1 in your release profile. Use PGO (Profile-Guided Optimisation) for a further 10–20% improvement on Windows.

Optimise Rust release builds on Windows

Cargo.toml
[profile.release]
opt-level = 3 # max speed (default for release)
lto = "thin" # thin LTO: good balance
codegen-units = 1 # enables cross-crate optimisation
panic = "abort" # smaller binary, no unwinding
strip = "symbols" # remove debug symbols

Profile-Guided Optimisation on Windows

PGO uses real workload data to guide compiler optimisations, typically giving 10–20% speedup:

PowerShell — PGO workflow
# Step 1: Build instrumented binary:
PS> $env:RUSTFLAGS="-Cprofile-generate=C:\pgo-data"
PS> cargo build --release
# Step 2: Run the binary with representative workload:
PS> .\target\release\your-app.exe [typical inputs]
# Step 3: Merge profiles (requires llvm-profdata):
PS> llvm-profdata merge -o merged.profdata C:\pgo-data\*.profraw
# Step 4: Build with profile data:
PS> $env:RUSTFLAGS="-Cprofile-use=merged.profdata"
PS> cargo build --release

Benchmark Rust code on Windows

PowerShell
# Install hyperfine for CLI benchmarking:
PS> cargo install hyperfine
PS> hyperfine ".\target\release\your-app.exe"
# Use criterion for micro-benchmarks:
# Add to Cargo.toml:
[[bench]]
name = "my_bench"
harness = false
PS> cargo bench

Performance questions

How fast is Rust compared to C++ on Windows?

Rust and C++ are within a few percent of each other on CPU-bound benchmarks. Both use LLVM on Windows and produce similar machine code. With identical optimisation settings (LTO, codegen-units=1), they are effectively equivalent. The Computer Language Benchmarks Game shows Rust and C++ alternating first place depending on the benchmark.

Why is my Rust debug build slow?

Debug builds (cargo build without --release) use opt-level = 0 and include debug information. Add opt-level = 1 to your [profile.dev] section in Cargo.toml for faster debug builds with minimal impact on compile time.