Make benchmarks work on stable
This commit is contained in:
parent
afd46067a9
commit
a5aa7df51d
@ -12,5 +12,10 @@ keywords = ["statistics", "stats"]
|
||||
conv = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
bencher = "0.1"
|
||||
rand = "0.3"
|
||||
streaming-stats = "0.1"
|
||||
|
||||
[[bench]]
|
||||
name = "average"
|
||||
harness = false
|
||||
|
39
benches/average.rs
Normal file
39
benches/average.rs
Normal file
@ -0,0 +1,39 @@
|
||||
#[macro_use] extern crate bencher;
|
||||
extern crate rand;
|
||||
|
||||
extern crate average;
|
||||
extern crate stats;
|
||||
|
||||
use bencher::Bencher;
|
||||
|
||||
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_average(b: &mut Bencher) {
|
||||
let values = initialize_vec();
|
||||
b.iter(|| {
|
||||
let a: average::Average = values.iter().map(|x| *x).collect();
|
||||
a
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_stats(b: &mut Bencher) {
|
||||
let values = initialize_vec();
|
||||
b.iter(|| {
|
||||
let a: stats::OnlineStats = values.iter().map(|x| *x).collect();
|
||||
a
|
||||
});
|
||||
}
|
||||
|
||||
benchmark_group!(benches, bench_average, bench_stats);
|
||||
benchmark_main!(benches);
|
35
src/lib.rs
35
src/lib.rs
@ -1,11 +1,8 @@
|
||||
#![no_std]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate conv;
|
||||
#[cfg(test)] extern crate rand;
|
||||
#[cfg(test)] #[macro_use] extern crate std;
|
||||
#[cfg(test)] extern crate stats;
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
use conv::ApproxFrom;
|
||||
|
||||
@ -159,7 +156,6 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use core::iter::Iterator;
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn average_trivial() {
|
||||
@ -216,35 +212,4 @@ mod tests {
|
||||
assert_eq!(avg_total.v, avg_left.v);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_average(b: &mut test::Bencher) {
|
||||
let values = initialize_vec();
|
||||
b.iter(|| {
|
||||
let a: Average = values.iter().map(|x| *x).collect();
|
||||
a
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_stats(b: &mut test::Bencher) {
|
||||
let values = initialize_vec();
|
||||
b.iter(|| {
|
||||
let a: stats::OnlineStats = values.iter().map(|x| *x).collect();
|
||||
a
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user