2014-11-07 15:13:54 +00:00
|
|
|
// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
|
2015-03-14 02:44:59 +00:00
|
|
|
// refer to the Cargo.toml file at the top-level directory of this distribution.
|
2014-11-07 15:13:54 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-12-22 11:55:59 +00:00
|
|
|
macro_rules! bench_binop {
|
2014-11-07 15:13:54 +00:00
|
|
|
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
|
|
|
#[bench]
|
|
|
|
fn $name(bh: &mut Bencher) {
|
2015-01-09 23:16:39 +00:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2020-06-03 23:40:02 +00:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2015-03-18 17:13:21 +00:00
|
|
|
let elems1: Vec<$t1> = (0..LEN).map(|_| rng.gen::<$t1>()).collect();
|
|
|
|
let elems2: Vec<$t2> = (0..LEN).map(|_| rng.gen::<$t2>()).collect();
|
2014-11-07 15:13:54 +00:00
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
bh.iter(|| {
|
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
2019-11-05 06:16:38 +00:00
|
|
|
unsafe { test::black_box(elems1.get_unchecked(i).$binop(*elems2.get_unchecked(i))) }
|
2014-11-07 15:13:54 +00:00
|
|
|
})
|
|
|
|
}
|
2015-12-22 11:55:59 +00:00
|
|
|
};
|
|
|
|
}
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2015-12-22 11:55:59 +00:00
|
|
|
macro_rules! bench_unop {
|
2014-11-07 15:13:54 +00:00
|
|
|
($name: ident, $t: ty, $unop: ident) => {
|
|
|
|
#[bench]
|
|
|
|
fn $name(bh: &mut Bencher) {
|
2015-01-09 23:16:39 +00:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2020-06-03 23:40:02 +00:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2015-03-18 17:13:21 +00:00
|
|
|
let mut elems: Vec<$t> = (0..LEN).map(|_| rng.gen::<$t>()).collect();
|
2014-11-07 15:13:54 +00:00
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
bh.iter(|| {
|
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
2019-11-05 06:16:38 +00:00
|
|
|
unsafe { test::black_box(elems.get_unchecked_mut(i).$unop()) }
|
2014-11-07 15:13:54 +00:00
|
|
|
})
|
|
|
|
}
|
2015-12-22 11:55:59 +00:00
|
|
|
};
|
|
|
|
}
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2015-12-22 11:55:59 +00:00
|
|
|
macro_rules! bench_construction {
|
2015-01-09 22:59:43 +00:00
|
|
|
($name: ident, $t: ty, $constructor: path [ $($args: ident: $types: ty),+ ]) => {
|
2014-11-07 15:13:54 +00:00
|
|
|
#[bench]
|
|
|
|
fn $name(bh: &mut Bencher) {
|
2015-01-09 23:16:39 +00:00
|
|
|
const LEN: usize = 1 << 13;
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2020-06-03 23:40:02 +00:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
2014-11-07 15:13:54 +00:00
|
|
|
|
2015-03-18 17:13:21 +00:00
|
|
|
$(let $args: Vec<$types> = (0..LEN).map(|_| rng.gen::<$types>()).collect();)*
|
2014-11-07 15:13:54 +00:00
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
bh.iter(|| {
|
|
|
|
i = (i + 1) & (LEN - 1);
|
|
|
|
|
|
|
|
unsafe {
|
2015-01-07 22:34:42 +00:00
|
|
|
let res: $t = $constructor($(*$args.get_unchecked(i),)*);
|
2014-11-07 15:13:54 +00:00
|
|
|
test::black_box(res)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2015-12-22 11:55:59 +00:00
|
|
|
};
|
|
|
|
}
|