https://github.com/rust-dd/probability-benchmark
🦀 Scientific Computing Benchmark: Rust 🦀 vs Zig ⚡ vs the father C 👴
https://github.com/rust-dd/probability-benchmark
c ornstein-uhlenbeck-process rust stochastic-processes zig
Last synced: 2 months ago
JSON representation
🦀 Scientific Computing Benchmark: Rust 🦀 vs Zig ⚡ vs the father C 👴
- Host: GitHub
- URL: https://github.com/rust-dd/probability-benchmark
- Owner: rust-dd
- Created: 2025-07-07T20:22:40.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-07T22:28:23.000Z (11 months ago)
- Last Synced: 2025-07-07T23:36:34.714Z (11 months ago)
- Topics: c, ornstein-uhlenbeck-process, rust, stochastic-processes, zig
- Language: Zig
- Homepage: https://rust-dd.com/post/crab-scientific-computing-benchmark-rust-crab-vs-zig-zap-vs-the-father-c-older_man
- Size: 11.8 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🦀 Probability Benchmark: Rust vs Zig vs 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.
## 💡 What is it about?
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:
- \(\theta\) = mean reversion speed
- \(\mu\) = long-term mean
- \(\sigma\) = volatility
- \(dW_t\) = standard Brownian motion increment
---
## ⚡ Motivation
As the maintainer of [stochastic-rs](https://github.com/dancixx/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.
---
## 💻 Code snippets
### Rust (🦀)
- Uses `rand` and `rand_distr`
- Run with: `cargo run --release`
[See code here](./rust_version.rs)
---
### Zig (⚡)
- Uses [zprob](https://github.com/pblischak/zprob)
- Run with: `zig build run -Doptimize=ReleaseFast`
[See code here](./zig_version.zig)
---
### C (👴)
- Simple Box-Muller method for normal sampling
- Compile with: `gcc -O3 -march=native -o main main.c -lm`
[See code here](./c_version.c)
---
Természetesen! Íme **vesszők nélkül**, szépen formázva:
---
## 📊 Results
| 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) |
---
## 🗣️ Discussion
This benchmark is not intended to be a definitive performance proof, but rather a fun exploration. Contributions, improvements, or corrections are highly welcome!
👉 [Join the discussion](https://github.com/rust-dd/probability-benchmark/discussions/1)
---
## 📎 License
MIT
---
**Enjoy, and happy benchmarking! 🚀**