Skip to content

Commit 699bd5d

Browse files
committed
feat: update benchmarks
1 parent b5f3d00 commit 699bd5d

2 files changed

Lines changed: 210 additions & 22 deletions

File tree

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,43 @@ Interpretation:
169169
- CUDA wins for large single-path generation (from roughly `n >= 16k` in this setup).
170170
- For the tested batch sizes, CPU `sample_par` is faster than current CUDA path.
171171

172-
### Distribution Sampling (Compact Summary)
173-
174-
SIMD distribution sampling (`stochastic-rs`) vs `rand_distr` measured with Criterion (`benches/distributions.rs`).
175-
176-
| Distribution family | Observed speedup range |
177-
|---|---:|
178-
| Normal | 2.88x - 3.37x |
179-
| Exponential | 4.81x - 5.19x |
180-
| LogNormal | 2.62x - 2.83x |
181-
| Cauchy | 1.67x - 4.37x |
182-
| Gamma | 2.34x - 2.71x |
183-
| Weibull | 1.46x - 1.47x |
184-
| Beta | 3.42x - 4.12x |
185-
| ChiSquared | 2.39x - 2.71x |
186-
| StudentT | 2.63x - 2.97x |
187-
| Poisson | 5.11x |
188-
| Pareto | 2.10x - 2.27x |
189-
| Uniform | ~1.00x |
172+
### Distribution Sampling (All Built-in Distributions)
173+
174+
Measured with:
175+
176+
```bash
177+
cargo bench --bench dist_multicore
178+
```
179+
180+
Configuration in this run:
181+
- `sample_matrix` benchmark
182+
- 1-thread vs 14-thread rayon pools
183+
- size is mostly `1024 x 1024`; heavy discrete samplers use `512 x 512`
184+
185+
| Distribution | Shape | 1T (ms) | MT (ms) | Speedup |
186+
|---|---:|---:|---:|---:|
187+
| Normal<f64> | 1024 x 1024 | 1.78 | 0.34 | 5.28x |
188+
| Exp<f64> | 1024 x 1024 | 1.73 | 0.33 | 5.25x |
189+
| Uniform<f64> | 1024 x 1024 | 0.65 | 0.13 | 5.12x |
190+
| Cauchy<f64> | 1024 x 1024 | 6.23 | 0.90 | 6.96x |
191+
| LogNormal<f64> | 1024 x 1024 | 5.07 | 0.81 | 6.25x |
192+
| Gamma<f64> | 1024 x 1024 | 5.20 | 0.72 | 7.19x |
193+
| ChiSq<f64> | 1024 x 1024 | 5.06 | 1.22 | 4.14x |
194+
| StudentT<f64> | 1024 x 1024 | 7.89 | 1.89 | 4.18x |
195+
| Beta<f64> | 1024 x 1024 | 11.85 | 1.68 | 7.04x |
196+
| Weibull<f64> | 1024 x 1024 | 13.17 | 1.73 | 7.59x |
197+
| Pareto<f64> | 1024 x 1024 | 5.48 | 0.80 | 6.87x |
198+
| InvGauss<f64> | 1024 x 1024 | 2.52 | 0.44 | 5.69x |
199+
| NIG<f64> | 1024 x 1024 | 5.93 | 0.90 | 6.62x |
200+
| AlphaStable<f64> | 1024 x 1024 | 42.52 | 5.36 | 7.94x |
201+
| Poisson<i64> | 1024 x 1024 | 2.28 | 0.42 | 5.40x |
202+
| Geometric<u64> | 1024 x 1024 | 2.75 | 0.44 | 6.30x |
203+
| Binomial<u32> | 512 x 512 | 4.43 | 0.70 | 6.32x |
204+
| Hypergeo<u32> | 512 x 512 | 20.99 | 2.76 | 7.60x |
205+
206+
`Normal` single-thread kernel comparison (`fill_slice`, same run):
207+
- vs `rand_distr + SimdRng`: ~`1.21x` to `1.35x`
208+
- vs `rand_distr + rand::rng()`: ~`4.09x` to `4.61x`
190209

191210
## Contributing
192211

benches/dist_multicore.rs

Lines changed: 173 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ use rand_distr::Distribution;
55
use rayon::ThreadPool;
66
use rayon::ThreadPoolBuilder;
77
use stochastic_rs::distributions::DistributionSampler;
8+
use stochastic_rs::distributions::alpha_stable::SimdAlphaStable;
9+
use stochastic_rs::distributions::beta::SimdBeta;
10+
use stochastic_rs::distributions::binomial::SimdBinomial;
11+
use stochastic_rs::distributions::cauchy::SimdCauchy;
12+
use stochastic_rs::distributions::chi_square::SimdChiSquared;
813
use stochastic_rs::distributions::exp::SimdExp;
14+
use stochastic_rs::distributions::gamma::SimdGamma;
15+
use stochastic_rs::distributions::geometric::SimdGeometric;
16+
use stochastic_rs::distributions::hypergeometric::SimdHypergeometric;
17+
use stochastic_rs::distributions::inverse_gauss::SimdInverseGauss;
18+
use stochastic_rs::distributions::lognormal::SimdLogNormal;
919
use stochastic_rs::distributions::normal::SimdNormal;
20+
use stochastic_rs::distributions::normal_inverse_gauss::SimdNormalInverseGauss;
21+
use stochastic_rs::distributions::pareto::SimdPareto;
1022
use stochastic_rs::distributions::poisson::SimdPoisson;
23+
use stochastic_rs::distributions::studentt::SimdStudentT;
24+
use stochastic_rs::distributions::uniform::SimdUniform;
25+
use stochastic_rs::distributions::weibull::SimdWeibull;
1126
use stochastic_rs::simd_rng::SimdRng;
1227

1328
fn median_ms(samples: &mut [f64]) -> f64 {
@@ -132,7 +147,7 @@ where
132147
let speedup = t1 / tn;
133148
let values = m * n;
134149
println!(
135-
"{name:>12} | m={m:<5} n={n:<5} values={values:<10} | 1T={t1:>8.2} ms | MT={tn:>8.2} ms | speedup={speedup:>5.2}x"
150+
"{name:>18} | m={m:<5} n={n:<5} values={values:<10} | 1T={t1:>8.2} ms | MT={tn:>8.2} ms | speedup={speedup:>5.2}x"
136151
);
137152
}
138153

@@ -155,30 +170,184 @@ fn main() {
155170
println!();
156171

157172
run_case(
158-
"Normal<f64>",
173+
"Normal<f64>(ref)",
159174
&SimdNormal::<f64>::new(0.0, 1.0),
160175
2048,
161176
2048,
162177
&single,
163178
&multi,
164179
);
165180
run_case(
166-
"Exp<f64>",
181+
"Exp<f64>(ref)",
167182
&SimdExp::<f64>::new(1.5),
168183
2048,
169184
2048,
170185
&single,
171186
&multi,
172187
);
173188
run_case(
174-
"Poisson<i64>",
189+
"Poisson<i64>(ref)",
175190
&SimdPoisson::<i64>::new(1.5),
176191
2048,
177192
2048,
178193
&single,
179194
&multi,
180195
);
181196

197+
println!();
198+
println!("All built-in distributions sample_matrix benchmark");
199+
println!("(sizes tuned to keep runtime practical for heavier discrete samplers)");
200+
let fm = 1024usize;
201+
let fnn = 1024usize;
202+
let im = 512usize;
203+
let inn = 512usize;
204+
205+
run_case(
206+
"Normal<f64>",
207+
&SimdNormal::<f64>::new(0.0, 1.0),
208+
fm,
209+
fnn,
210+
&single,
211+
&multi,
212+
);
213+
run_case(
214+
"Exp<f64>",
215+
&SimdExp::<f64>::new(1.5),
216+
fm,
217+
fnn,
218+
&single,
219+
&multi,
220+
);
221+
run_case(
222+
"Uniform<f64>",
223+
&SimdUniform::<f64>::new(0.0, 1.0),
224+
fm,
225+
fnn,
226+
&single,
227+
&multi,
228+
);
229+
run_case(
230+
"Cauchy<f64>",
231+
&SimdCauchy::<f64>::new(0.0, 1.0),
232+
fm,
233+
fnn,
234+
&single,
235+
&multi,
236+
);
237+
run_case(
238+
"LogNormal<f64>",
239+
&SimdLogNormal::<f64>::new(0.2, 0.8),
240+
fm,
241+
fnn,
242+
&single,
243+
&multi,
244+
);
245+
run_case(
246+
"Gamma<f64>",
247+
&SimdGamma::<f64>::new(2.0, 2.0),
248+
fm,
249+
fnn,
250+
&single,
251+
&multi,
252+
);
253+
run_case(
254+
"ChiSq<f64>",
255+
&SimdChiSquared::<f64>::new(5.0),
256+
fm,
257+
fnn,
258+
&single,
259+
&multi,
260+
);
261+
run_case(
262+
"StudentT<f64>",
263+
&SimdStudentT::<f64>::new(5.0),
264+
fm,
265+
fnn,
266+
&single,
267+
&multi,
268+
);
269+
run_case(
270+
"Beta<f64>",
271+
&SimdBeta::<f64>::new(2.0, 2.0),
272+
fm,
273+
fnn,
274+
&single,
275+
&multi,
276+
);
277+
run_case(
278+
"Weibull<f64>",
279+
&SimdWeibull::<f64>::new(1.0, 1.5),
280+
fm,
281+
fnn,
282+
&single,
283+
&multi,
284+
);
285+
run_case(
286+
"Pareto<f64>",
287+
&SimdPareto::<f64>::new(1.0, 1.5),
288+
fm,
289+
fnn,
290+
&single,
291+
&multi,
292+
);
293+
run_case(
294+
"InvGauss<f64>",
295+
&SimdInverseGauss::<f64>::new(1.0, 2.0),
296+
fm,
297+
fnn,
298+
&single,
299+
&multi,
300+
);
301+
run_case(
302+
"NIG<f64>",
303+
&SimdNormalInverseGauss::<f64>::new(2.0, 0.5, 1.0, 0.0),
304+
fm,
305+
fnn,
306+
&single,
307+
&multi,
308+
);
309+
run_case(
310+
"AlphaStable<f64>",
311+
&SimdAlphaStable::<f64>::new(1.7, 0.3, 1.0, 0.0),
312+
fm,
313+
fnn,
314+
&single,
315+
&multi,
316+
);
317+
318+
run_case(
319+
"Poisson<i64>",
320+
&SimdPoisson::<i64>::new(2.5),
321+
fm,
322+
fnn,
323+
&single,
324+
&multi,
325+
);
326+
run_case(
327+
"Geometric<u64>",
328+
&SimdGeometric::<u64>::new(0.3),
329+
fm,
330+
fnn,
331+
&single,
332+
&multi,
333+
);
334+
run_case(
335+
"Binomial<u32>",
336+
&SimdBinomial::<u32>::new(32, 0.3),
337+
im,
338+
inn,
339+
&single,
340+
&multi,
341+
);
342+
run_case(
343+
"Hypergeo<u32>",
344+
&SimdHypergeometric::<u32>::new(500, 80, 32),
345+
im,
346+
inn,
347+
&single,
348+
&multi,
349+
);
350+
182351
println!();
183352
println!("Normal fill_slice benchmark (single-thread)");
184353
println!("Reference A: rand_distr + SimdRng (fair algorithm compare)");

0 commit comments

Comments
 (0)