2015-01-08 04:11:09 +08:00
|
|
|
#![macro_use]
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
macro_rules! bench_binop(
|
|
|
|
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let a = rng.gen::<$t1>();
|
|
|
|
let b = rng.gen::<$t2>();
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2017-08-03 01:37:44 +08:00
|
|
|
a.$binop(b)
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
macro_rules! bench_binop_ref(
|
|
|
|
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let a = rng.gen::<$t1>();
|
|
|
|
let b = rng.gen::<$t2>();
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2017-08-03 01:37:44 +08:00
|
|
|
a.$binop(&b)
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
macro_rules! bench_binop_fn(
|
|
|
|
($name: ident, $t1: ty, $t2: ty, $binop: path) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2017-08-03 01:37:44 +08:00
|
|
|
let a = rng.gen::<$t1>();
|
|
|
|
let b = rng.gen::<$t2>();
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2017-08-03 01:37:44 +08:00
|
|
|
$binop(&a, &b)
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2016-12-05 05:44:42 +08:00
|
|
|
macro_rules! bench_unop_na(
|
2014-11-07 23:15:56 +08:00
|
|
|
($name: ident, $t: ty, $unop: ident) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2015-01-10 05:26:05 +08:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2015-04-18 20:19:43 +08:00
|
|
|
let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
|
2014-11-07 23:15:56 +08:00
|
|
|
let mut i = 0;
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2014-11-07 23:15:56 +08:00
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
|
|
|
unsafe {
|
2021-04-12 16:52:17 +08:00
|
|
|
std::hint::black_box(na::$unop(elems.get_unchecked(i)))
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2016-12-05 05:44:42 +08:00
|
|
|
macro_rules! bench_unop(
|
2014-11-07 23:15:56 +08:00
|
|
|
($name: ident, $t: ty, $unop: ident) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2015-01-10 05:26:05 +08:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2015-04-18 20:19:43 +08:00
|
|
|
let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
|
2014-11-07 23:15:56 +08:00
|
|
|
let mut i = 0;
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2014-11-07 23:15:56 +08:00
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
|
|
|
unsafe {
|
2021-04-12 16:52:17 +08:00
|
|
|
std::hint::black_box(elems.get_unchecked_mut(i).$unop())
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
|
|
|
macro_rules! bench_construction(
|
2015-01-10 05:52:44 +08:00
|
|
|
($name: ident, $constructor: path, $( $args: ident: $types: ty),*) => {
|
2019-03-24 01:01:04 +08:00
|
|
|
fn $name(bh: &mut criterion::Criterion) {
|
2015-01-10 05:26:05 +08:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2018-12-29 19:12:56 +08:00
|
|
|
use rand::SeedableRng;
|
|
|
|
let mut rng = IsaacRng::seed_from_u64(0);
|
2014-11-07 23:15:56 +08:00
|
|
|
|
2015-04-18 20:19:43 +08:00
|
|
|
$(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.gen::<$types>()).collect();)*
|
2014-11-07 23:15:56 +08:00
|
|
|
let mut i = 0;
|
|
|
|
|
2019-03-24 01:01:04 +08:00
|
|
|
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
|
2014-11-07 23:15:56 +08:00
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
|
|
|
unsafe {
|
2015-01-05 22:12:06 +08:00
|
|
|
let res = $constructor($(*$args.get_unchecked(i),)*);
|
2021-04-12 16:52:17 +08:00
|
|
|
std::hint::black_box(res)
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
2019-03-24 01:01:04 +08:00
|
|
|
}));
|
2014-11-07 23:15:56 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:15:13 +08:00
|
|
|
);
|