-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsummary_statistics.rs
35 lines (33 loc) · 1.12 KB
/
summary_statistics.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion, PlotConfiguration,
};
use ndarray::prelude::*;
use ndarray_rand::rand_distr::Uniform;
use ndarray_rand::RandomExt;
use ndarray_stats::SummaryStatisticsExt;
fn weighted_std(c: &mut Criterion) {
let lens = vec![10, 100, 1000, 10000];
let mut group = c.benchmark_group("weighted_std");
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
for len in &lens {
group.bench_with_input(format!("{}", len), len, |b, &len| {
let data = Array::random(len, Uniform::new(0.0, 1.0));
let mut weights = Array::random(len, Uniform::new(0.0, 1.0));
weights /= weights.sum();
b.iter_batched(
|| data.clone(),
|arr| {
black_box(arr.weighted_std(&weights, 0.0).unwrap());
},
BatchSize::SmallInput,
)
});
}
group.finish();
}
criterion_group! {
name = benches;
config = Criterion::default();
targets = weighted_std
}
criterion_main!(benches);