Improve benchmarks

This commit is contained in:
Vurich 2017-08-21 16:11:31 +02:00
parent 7aff9555e4
commit 1b9f3dcfab
1 changed files with 22 additions and 4 deletions

View File

@ -73,7 +73,16 @@ fn u512_mul(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
let one = black_box(U512::one());
(1..n).fold(one, |old, new| { old.overflowing_mul(U512::from(black_box(new))).0 })
(1..n).fold(one, |old, new| { old.overflowing_mul(U512::from(black_box(new | 1))).0 })
});
}
#[bench]
fn u512_mul_small(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
let one = black_box(U512::one());
(1..153).fold(one, |old, new| { old.overflowing_mul(U512::from(10)).0 })
});
}
@ -82,7 +91,16 @@ fn u256_mul(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
let one = black_box(U256::one());
(1..n).fold(one, |old, new| { old.overflowing_mul(U256::from(black_box(new))).0 })
(1..n).fold(one, |old, new| { old.overflowing_mul(U256::from(black_box(new | 1))).0 })
});
}
#[bench]
fn u256_mul_small(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
let one = black_box(U256::one());
(1..77).fold(one, |old, new| { old.overflowing_mul(U256::from(10)).0 })
});
}
@ -91,7 +109,7 @@ fn u256_full_mul(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
let one = black_box(U256::one());
(1..n).fold(one,
(1..n).map(|n| n | 1).fold(one,
|old, new| {
let new = black_box(new);
let U512(ref u512words) = old.full_mul(U256([new, new, new, new]));
@ -105,7 +123,7 @@ fn u256_full_mul(b: &mut Bencher) {
fn u128_mul(b: &mut Bencher) {
b.iter(|| {
let n = black_box(10000);
(1..n).fold(U128([12345u64, 0u64]), |old, new| { old.overflowing_mul(U128::from(new)).0 })
(1..n).fold(U128([12345u64, 0u64]), |old, new| { old.overflowing_mul(U128::from(new | 1)).0 })
});
}