Benchmark generic vs. handwritten implementation of kurtosis
Also restore no_std and remove printing left over from debugging.
This commit is contained in:
parent
785e2141e0
commit
a6a477d621
@ -18,6 +18,10 @@ name = "mean"
|
|||||||
harness = false
|
harness = false
|
||||||
name = "min"
|
name = "min"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
harness = false
|
||||||
|
name = "kurtosis"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
num-traits = "0.1"
|
num-traits = "0.1"
|
||||||
num-integer = "0.1"
|
num-integer = "0.1"
|
||||||
|
41
benches/kurtosis.rs
Normal file
41
benches/kurtosis.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, map_clone))]
|
||||||
|
|
||||||
|
#[macro_use] extern crate bencher;
|
||||||
|
extern crate rand;
|
||||||
|
|
||||||
|
extern crate average;
|
||||||
|
|
||||||
|
use bencher::Bencher;
|
||||||
|
|
||||||
|
/// Create a random vector by sampling from a normal distribution.
|
||||||
|
fn initialize_vec() -> Vec<f64> {
|
||||||
|
use rand::distributions::{Normal, IndependentSample};
|
||||||
|
use rand::{XorShiftRng, SeedableRng};
|
||||||
|
let normal = Normal::new(2.0, 3.0);
|
||||||
|
let n = 1_000_000;
|
||||||
|
let mut values = Vec::with_capacity(n);
|
||||||
|
let mut rng = XorShiftRng::from_seed([1, 2, 3, 4]);
|
||||||
|
for _ in 0..n {
|
||||||
|
values.push(normal.ind_sample(&mut rng));
|
||||||
|
}
|
||||||
|
values
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_kurtosis(b: &mut Bencher) {
|
||||||
|
let values = initialize_vec();
|
||||||
|
b.iter(|| {
|
||||||
|
let m: average::Kurtosis = values.iter().map(|x| *x).collect();
|
||||||
|
m
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_moments(b: &mut Bencher) {
|
||||||
|
let values = initialize_vec();
|
||||||
|
b.iter(|| {
|
||||||
|
let m: average::Moments = values.iter().map(|x| *x).collect();
|
||||||
|
m
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmark_group!(benches, bench_kurtosis, bench_moments);
|
||||||
|
benchmark_main!(benches);
|
@ -74,8 +74,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
|
|
||||||
//#![no_std]
|
#![no_std]
|
||||||
extern crate core;
|
|
||||||
|
|
||||||
extern crate conv;
|
extern crate conv;
|
||||||
extern crate quickersort;
|
extern crate quickersort;
|
||||||
|
@ -46,7 +46,6 @@ impl Kurtosis {
|
|||||||
+ 6. * delta_n_sq * self.avg.avg.sum_2
|
+ 6. * delta_n_sq * self.avg.avg.sum_2
|
||||||
- 4. * delta_n * self.avg.sum_3;
|
- 4. * delta_n * self.avg.sum_3;
|
||||||
self.avg.add_inner(delta, delta_n);
|
self.avg.add_inner(delta, delta_n);
|
||||||
println!("skewness={} kurtosis={}", self.skewness(), self.kurtosis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine whether the sample is empty.
|
/// Determine whether the sample is empty.
|
||||||
|
Loading…
Reference in New Issue
Block a user