rust-dd/probability-benchmark
🦀 Scientific Computing Benchmark: Rust 🦀 vs Zig ⚡ vs the father C 👴
This repository benchmarks three languages — Rust, Zig, and C — for generating Ornstein–Uhlenbeck (OU) stochastic processes, commonly used in stochastic calculus and mathematical finance.
We simulate 1,000 trajectories, each of length 500,000, using a simple Euler scheme. Each trajectory uses normally distributed increments to generate a mean-reverting process.
Mathematically, the OU process is given by:
[ dX_t = \theta (\mu - X_t),dt + \sigma,dW_t ]
where:
As the maintainer of stochastic-rs, I'm a big fan of low-level, hardware-oriented programming languages, especially for scientific computing.
I’m not an expert in Zig or C, so this benchmark represents what might happen if a "regular Rust user" tries to quickly hack together similar code in other languages after a bit of Googling and reading docs.
rand
and rand_distr
cargo run --release
zig build run -Doptimize=ReleaseFast
gcc -O3 -march=native -o main main.c -lm
Természetesen! Íme vesszők nélkül, szépen formázva:
Language | Avg (ms) | Total (ms) |
---|---|---|
Rust 🦀 | 3.08 ms | 3077 ms (~3.1 sec) |
Zig ⚡ | 3.58 ms | 3584 ms (~3.6 sec) |
C 👴 | 3.61 ms | 3611 ms (~3.6 sec) |
This benchmark is not intended to be a definitive performance proof, but rather a fun exploration. Contributions, improvements, or corrections are highly welcome!
MIT
Enjoy, and happy benchmarking! 🚀