Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
This commit is contained in:
34
vendor/rand/benches/bench.rs
vendored
Normal file
34
vendor/rand/benches/bench.rs
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
extern crate rand;
|
||||
|
||||
const RAND_BENCH_N: u64 = 1000;
|
||||
|
||||
mod distributions;
|
||||
|
||||
use std::mem::size_of;
|
||||
use test::{black_box, Bencher};
|
||||
use rand::{StdRng, Rng};
|
||||
|
||||
#[bench]
|
||||
fn rand_f32(b: &mut Bencher) {
|
||||
let mut rng = StdRng::new().unwrap();
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
black_box(rng.next_f32());
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f32>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn rand_f64(b: &mut Bencher) {
|
||||
let mut rng = StdRng::new().unwrap();
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
black_box(rng.next_f64());
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
}
|
18
vendor/rand/benches/distributions/exponential.rs
vendored
Normal file
18
vendor/rand/benches/distributions/exponential.rs
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
use std::mem::size_of;
|
||||
use test::Bencher;
|
||||
use rand;
|
||||
use rand::distributions::exponential::Exp;
|
||||
use rand::distributions::Sample;
|
||||
|
||||
#[bench]
|
||||
fn rand_exp(b: &mut Bencher) {
|
||||
let mut rng = rand::weak_rng();
|
||||
let mut exp = Exp::new(2.71828 * 3.14159);
|
||||
|
||||
b.iter(|| {
|
||||
for _ in 0..::RAND_BENCH_N {
|
||||
exp.sample(&mut rng);
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
|
||||
}
|
31
vendor/rand/benches/distributions/gamma.rs
vendored
Normal file
31
vendor/rand/benches/distributions/gamma.rs
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
use std::mem::size_of;
|
||||
use test::Bencher;
|
||||
use rand;
|
||||
use rand::distributions::IndependentSample;
|
||||
use rand::distributions::gamma::Gamma;
|
||||
|
||||
#[bench]
|
||||
fn bench_gamma_large_shape(b: &mut Bencher) {
|
||||
let gamma = Gamma::new(10., 1.0);
|
||||
let mut rng = rand::weak_rng();
|
||||
|
||||
b.iter(|| {
|
||||
for _ in 0..::RAND_BENCH_N {
|
||||
gamma.ind_sample(&mut rng);
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_gamma_small_shape(b: &mut Bencher) {
|
||||
let gamma = Gamma::new(0.1, 1.0);
|
||||
let mut rng = rand::weak_rng();
|
||||
|
||||
b.iter(|| {
|
||||
for _ in 0..::RAND_BENCH_N {
|
||||
gamma.ind_sample(&mut rng);
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
|
||||
}
|
3
vendor/rand/benches/distributions/mod.rs
vendored
Normal file
3
vendor/rand/benches/distributions/mod.rs
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
mod exponential;
|
||||
mod normal;
|
||||
mod gamma;
|
18
vendor/rand/benches/distributions/normal.rs
vendored
Normal file
18
vendor/rand/benches/distributions/normal.rs
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
use std::mem::size_of;
|
||||
use test::Bencher;
|
||||
use rand;
|
||||
use rand::distributions::Sample;
|
||||
use rand::distributions::normal::Normal;
|
||||
|
||||
#[bench]
|
||||
fn rand_normal(b: &mut Bencher) {
|
||||
let mut rng = rand::weak_rng();
|
||||
let mut normal = Normal::new(-2.71828, 3.14159);
|
||||
|
||||
b.iter(|| {
|
||||
for _ in 0..::RAND_BENCH_N {
|
||||
normal.sample(&mut rng);
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
|
||||
}
|
133
vendor/rand/benches/generators.rs
vendored
Normal file
133
vendor/rand/benches/generators.rs
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
extern crate rand;
|
||||
|
||||
const RAND_BENCH_N: u64 = 1000;
|
||||
const BYTES_LEN: usize = 1024;
|
||||
|
||||
use std::mem::size_of;
|
||||
use test::{black_box, Bencher};
|
||||
|
||||
use rand::{Rng, StdRng, OsRng, JitterRng};
|
||||
use rand::{XorShiftRng, IsaacRng, Isaac64Rng, ChaChaRng};
|
||||
|
||||
macro_rules! gen_bytes {
|
||||
($fnn:ident, $gen:ident) => {
|
||||
#[bench]
|
||||
fn $fnn(b: &mut Bencher) {
|
||||
let mut rng: $gen = OsRng::new().unwrap().gen();
|
||||
let mut buf = [0u8; BYTES_LEN];
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
rng.fill_bytes(&mut buf);
|
||||
black_box(buf);
|
||||
}
|
||||
});
|
||||
b.bytes = BYTES_LEN as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! gen_bytes_new {
|
||||
($fnn:ident, $gen:ident) => {
|
||||
#[bench]
|
||||
fn $fnn(b: &mut Bencher) {
|
||||
let mut rng = $gen::new().unwrap();
|
||||
let mut buf = [0u8; BYTES_LEN];
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
rng.fill_bytes(&mut buf);
|
||||
black_box(buf);
|
||||
}
|
||||
});
|
||||
b.bytes = BYTES_LEN as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gen_bytes!(gen_bytes_xorshift, XorShiftRng);
|
||||
gen_bytes!(gen_bytes_isaac, IsaacRng);
|
||||
gen_bytes!(gen_bytes_isaac64, Isaac64Rng);
|
||||
gen_bytes!(gen_bytes_chacha, ChaChaRng);
|
||||
gen_bytes_new!(gen_bytes_std, StdRng);
|
||||
gen_bytes_new!(gen_bytes_os, OsRng);
|
||||
|
||||
|
||||
macro_rules! gen_uint {
|
||||
($fnn:ident, $ty:ty, $gen:ident) => {
|
||||
#[bench]
|
||||
fn $fnn(b: &mut Bencher) {
|
||||
let mut rng: $gen = OsRng::new().unwrap().gen();
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
black_box(rng.gen::<$ty>());
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! gen_uint_new {
|
||||
($fnn:ident, $ty:ty, $gen:ident) => {
|
||||
#[bench]
|
||||
fn $fnn(b: &mut Bencher) {
|
||||
let mut rng = $gen::new().unwrap();
|
||||
b.iter(|| {
|
||||
for _ in 0..RAND_BENCH_N {
|
||||
black_box(rng.gen::<$ty>());
|
||||
}
|
||||
});
|
||||
b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gen_uint!(gen_u32_xorshift, u32, XorShiftRng);
|
||||
gen_uint!(gen_u32_isaac, u32, IsaacRng);
|
||||
gen_uint!(gen_u32_isaac64, u32, Isaac64Rng);
|
||||
gen_uint!(gen_u32_chacha, u32, ChaChaRng);
|
||||
gen_uint_new!(gen_u32_std, u32, StdRng);
|
||||
gen_uint_new!(gen_u32_os, u32, OsRng);
|
||||
|
||||
gen_uint!(gen_u64_xorshift, u64, XorShiftRng);
|
||||
gen_uint!(gen_u64_isaac, u64, IsaacRng);
|
||||
gen_uint!(gen_u64_isaac64, u64, Isaac64Rng);
|
||||
gen_uint!(gen_u64_chacha, u64, ChaChaRng);
|
||||
gen_uint_new!(gen_u64_std, u64, StdRng);
|
||||
gen_uint_new!(gen_u64_os, u64, OsRng);
|
||||
|
||||
#[bench]
|
||||
fn gen_u64_jitter(b: &mut Bencher) {
|
||||
let mut rng = JitterRng::new().unwrap();
|
||||
b.iter(|| {
|
||||
black_box(rng.gen::<u64>());
|
||||
});
|
||||
b.bytes = size_of::<u64>() as u64;
|
||||
}
|
||||
|
||||
macro_rules! init_gen {
|
||||
($fnn:ident, $gen:ident) => {
|
||||
#[bench]
|
||||
fn $fnn(b: &mut Bencher) {
|
||||
let mut rng: XorShiftRng = OsRng::new().unwrap().gen();
|
||||
b.iter(|| {
|
||||
let r2: $gen = rng.gen();
|
||||
black_box(r2);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_gen!(init_xorshift, XorShiftRng);
|
||||
init_gen!(init_isaac, IsaacRng);
|
||||
init_gen!(init_isaac64, Isaac64Rng);
|
||||
init_gen!(init_chacha, ChaChaRng);
|
||||
|
||||
#[bench]
|
||||
fn init_jitter(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
black_box(JitterRng::new().unwrap());
|
||||
});
|
||||
}
|
62
vendor/rand/benches/misc.rs
vendored
Normal file
62
vendor/rand/benches/misc.rs
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
extern crate rand;
|
||||
|
||||
use test::{black_box, Bencher};
|
||||
|
||||
use rand::{Rng, weak_rng};
|
||||
use rand::seq::*;
|
||||
|
||||
#[bench]
|
||||
fn misc_shuffle_100(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
let x : &mut [usize] = &mut [1; 100];
|
||||
b.iter(|| {
|
||||
rng.shuffle(x);
|
||||
black_box(&x);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn misc_sample_iter_10_of_100(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
let x : &[usize] = &[1; 100];
|
||||
b.iter(|| {
|
||||
black_box(sample_iter(&mut rng, x, 10).unwrap_or_else(|e| e));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn misc_sample_slice_10_of_100(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
let x : &[usize] = &[1; 100];
|
||||
b.iter(|| {
|
||||
black_box(sample_slice(&mut rng, x, 10));
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn misc_sample_slice_ref_10_of_100(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
let x : &[usize] = &[1; 100];
|
||||
b.iter(|| {
|
||||
black_box(sample_slice_ref(&mut rng, x, 10));
|
||||
})
|
||||
}
|
||||
|
||||
macro_rules! sample_indices {
|
||||
($name:ident, $amount:expr, $length:expr) => {
|
||||
#[bench]
|
||||
fn $name(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| {
|
||||
black_box(sample_indices(&mut rng, $length, $amount));
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sample_indices!(misc_sample_indices_10_of_1k, 10, 1000);
|
||||
sample_indices!(misc_sample_indices_50_of_1k, 50, 1000);
|
||||
sample_indices!(misc_sample_indices_100_of_1k, 100, 1000);
|
Reference in New Issue
Block a user