Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
criterion-stats 0.3.0 - Docs.rs
[go: Go Back, main page]

criterion-stats 0.3.0

Criterion's statistics library
Documentation
#[macro_use]
extern crate criterion;
extern crate criterion_stats as stats;
extern crate itertools_num;
extern crate rand;

mod common_bench;

macro_rules! bench {
    ($ty:ident) => {
        pub mod $ty {
            use criterion::Criterion;
            use stats::univariate::kde::kernel::Gaussian;
            use stats::univariate::kde::{Bandwidth, Kde};
            use stats::univariate::Sample;

            const KDE_POINTS: usize = 100;
            const SAMPLE_SIZE: usize = 100_000;

            fn call(c: &mut Criterion) {
                let data = ::common_bench::vec::<$ty>();

                c.bench_function(
                    &format!("univariate_kde_call_{}", stringify!($ty)),
                    move |b| {
                        let kde = Kde::new(Sample::new(&data), Gaussian, Bandwidth::Silverman);
                        let x = Sample::new(&data).mean();
                        b.iter(|| kde.estimate(x))
                    },
                );
            }

            fn map(c: &mut Criterion) {
                let data = ::common_bench::vec_sized(SAMPLE_SIZE).unwrap();
                let xs: Vec<_> = ::itertools_num::linspace::<$ty>(0., 1., KDE_POINTS).collect();

                c.bench_function(
                    &format!("univariate_kde_map_{}", stringify!($ty)),
                    move |b| {
                        let kde = Kde::new(Sample::new(&data), Gaussian, Bandwidth::Silverman);
                        b.iter(|| kde.map(&xs))
                    },
                );
            }

            criterion_group! {
                name = benches;
                config = Criterion::default();
                targets = call, map
            }
        }
    };
}

mod bench {
    bench!(f32);
    bench!(f64);
}

criterion_main!(bench::f32::benches, bench::f64::benches);